MKDIR, CHDIR and RMDIR

Discussions related to database technologies, file handling, directories and storage
Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

MKDIR, CHDIR and RMDIR

Post by Ivan »

I'm currently working on a program to calculate and draw the most efficient use of expensive fabric. It a kind of simple database where I need to access directories and work with directories.

Is it in simple ways possible to emulate the following commands like: MKDIR, CHDIR and RMDIR

I took the example from http://www.bbcbasic.co.uk/bbcwin/manual ... ml#dirlist and added some code:

It seems to work as expected.

I can list and decide file types, but I can't find any easy examples like above named commands.

Code: Select all

                                  
      DIM filename$(999)
      count = 0
      PROClistdirectory

      FOR list = 1 TO count
        PRINT filename$(list)
      NEXT list

      END

      DEF PROClistdirectory
      LOCAL dir%, sh%, res%
      DIM dir% LOCAL 317
      SYS "FindFirstFile", "*.BBC", dir% TO sh%
      IF sh% <> -1 THEN
        REPEAT
          count += 1                                                :REM added to original example
          REM PRINT $$(dir%+44)
          filename$(count) = $$(dir%+44)
          SYS "FindNextFile", sh%, dir% TO res%                     :REM added to original example
        UNTIL res% = 0
        SYS "FindClose", sh%
      ENDIF
      ENDPROC

BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
DDRM

Re: MKDIR, CHDIR and RMDIR

Post by DDRM »

Hi Ivan,

These functions are available via star commands:
*MKDIR (or *MD)
*CHDIR (or *CD)
*RMDIR (or *RD)

If you use the star commands directly you need to define the target directory explicitly but you can use OSCLI to "wrap" the star commands, together with a variable directory name, for example

OSCLI "CD """+directory$+""""

would change to the directory defined in directory$. Note the use of triple quotes to include a quote in the string!

This is covered in more detail in the manual. Hope that helps.

Best wishes,

D
Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: MKDIR, CHDIR and RMDIR

Post by Ivan »

Hi DDRM,
ON ERROR PRINT ERR

root$ = "\"
dirname$ = "Testing"

OSCLI "CD """+root$+""""

OSCLI "MKDIR """+dirname$+""""

OSCLI "CD """+dirname$+""""
Works great, but I had to handle errors. The manual use END to stop errors, but stops the program...

Maybe you can shet a little light on error handling.

----------------------------------------------------------------

As I recall back in eighties did UniComal have an errorhandler, that was very nice to use.
TRAP
some error prone code (eg MKDIR existing name)
HANDLER
PRINT "Directory name exist!"
RETRY
ENDTRAP
Is it possible to do similar error handling in BBCBASIC?

Best regards,

Ivan
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
RichardRussell

Re: MKDIR, CHDIR and RMDIR

Post by RichardRussell »

Ivan wrote: Fri 05 Jun 2020, 19:05Is it possible to do similar error handling in BBCBASIC?
Yes, see here.
Ivan
Posts: 127
Joined: Tue 07 May 2019, 16:47

Re: MKDIR, CHDIR and RMDIR

Post by Ivan »

Below the output and code by UniComal. The code catch the error and continues by the retry.

I am trying to do the same in BBCBASIC, but I think I don't understand the concept..?

trap-handling.jpg

Code: Select all

      oops = FALSE
      ON ERROR LOCAL IF FALSE THEN
        CASE oops OF
          WHEN FALSE
            PRINT "2/0 ";2/0
          WHEN TRUE
            PRINT "I'm back!"
          OTHERWISE
            PRINT "What?"
        ENDCASE
      ELSE
        CASE ERR OF
          WHEN 18:
            oops = TRUE
            PRINT "I'll be back"
          OTHERWISE RESTORE ERROR : ERROR ERR, REPORT$
        ENDCASE
      ENDIF : RESTORE ERROR
You do not have the required permissions to view the files attached to this post.
BBC Model B - 1984-1989. 6502 assembler, Unicomal 1988-1994, Some C and C++, Pascal 1990-1994. Bought a copy of BBC-BASIC 2007, but started to program at a daily basis 2019. C++ in 2021.
RichardRussell

Re: MKDIR, CHDIR and RMDIR

Post by RichardRussell »

Ivan wrote: Sat 06 Jun 2020, 11:50 I am trying to do the same in BBCBASIC, but I think I don't understand the concept..?
The Wiki article I linked to describes the BBC BASIC equivalent of the conventional TRY...CATCH style of Structured Exception Handling (e.g. as used in C++), which does not support a RETRY statement, or anything similar as far as I know. I wonder if RETRY is really what you want here, but if it is I would suggest that you simply roll-your-own equivalent using ON ERROR LOCAL rather than going down the SEH route:

Code: Select all

      oops = FALSE
      ON ERROR LOCAL oops = TRUE
      CASE oops OF
        WHEN FALSE
          PRINT "2/0: ";2/0
        WHEN TRUE
          PRINT "I'll be back!"
          PRINT "Error code: ";ERR
          PRINT REPORT$
          PRINT "0/2: ";0/2
          PRINT "I'm back!"
      ENDCASE
      RESTORE ERROR