BBC BASIC
Programming >> Database and Files >> Extracting a file list type (+data management
http://bbcbasic.conforums.com/index.cgi?board=database&action=display&num=1512532249

Extracting a file list type (+data management
Post by michael on Dec 6th, 2017, 02:50am

A NOTE: The following posts will be to do with file and data management for a special cross platform tool.



I had wanted to have a program to extract all the type of files I wanted my program to know so I could make a scrolling window for non windows type applications.

So I did some modifications to this program I found in help documents and added a routine to show the stored files.

So this program will get only the ".bbc" extension programs, and store them in the

my_files()

array.

Code:
      DIM my_file$(500):REM holds current files.Make this as big as you think you will need      c%=0      PROClistdirectory(".bbc")      REPEAT        PRINT my_file$(c%)        c%+=1      UNTIL my_file$(c%)=""      WAIT 1000      END      DEF PROClistdirectory(ext$)      LOCAL dir%, sh%, res%,cou%      DIM dir% LOCAL 317      SYS "FindFirstFile", "*", dir% TO sh%      IF sh% <> -1 THEN        REPEAT          f$= $$(dir%+44)          IF RIGHT$(f$,4)= ext$ THEN my_file$(cou%)=f$:cou%+=1          REM PRINT RIGHT$(f$,4):REM enable this to see the files it hides          SYS "FindNextFile", sh%, dir% TO res%        UNTIL res% = 0        SYS "FindClose", sh%      ENDIF      ENDPROC 

Re: Extracting a file list type (modification)
Post by Richard Russell on Dec 8th, 2017, 1:27pm

on Dec 6th, 2017, 02:50am, michael wrote:
I had wanted to have a program to extract all the type of files I wanted my program to know so I could make a scrolling window for non windows type applications.

When you say "non windows type applications" I'm not sure whether you mean 'non-GUI' or 'non-Windows'. Either way your program is BB4W-specific, which is undesirable given that this forum is principally intended to support BBCSDL, the cross-platform version of BBC BASIC.

I therefore offer below an alternative routine which is not platform-specific; it will run equally well on BB4W and BBCSDL (although note that when running on Linux or Mac OS the files won't necessarily be sorted alphabetically, as they usually will be on Windows).

The code has been adapted from the FNdirscan function in SDLIDE.bbc, which is of course freely available for anybody to use as a source of code ideas.

Richard.

Code:
      DIM my_file$(500) : REM Make this as big as you think you will need      num% = FNlistdirectory(my_file$(), "*.bbc")      IF num% THEN        FOR index% = 1 TO num%          PRINT my_file$(index%)        NEXT index%      ENDIF      END      DEF FNlistdirectory(RETURN name$(), filter$)      LOCAL F%, N%, a$      REM Spool *DIR output to a temporary file:      WIDTH 20      VDU 21      ON ERROR LOCAL IF FALSE THEN        OSCLI "spool """ + @tmp$ + "dir.tmp.txt"""        OSCLI "dir " + filter$      ENDIF : RESTORE ERROR      *spool      VDU 6      WIDTH 0      REM Parse the file to extract the filenames; cope with      REM long filenames if they have split between lines:      name$() = ""      F% = OPENIN(@tmp$ + "dir.tmp.txt")      WHILE NOT EOF#F% AND N% < DIM(name$(),1)        INPUT #F%,a$        IF ASC(a$)=&A a$ = MID$(a$,2)        IF LEFT$(a$,2) = "  " OR LEFT$(a$,2)= "* " THEN          IF a$ <> STRING$(20, " ") THEN            N% += 1            name$(N%) = MID$(a$,3)          ENDIF        ELSE          name$(N%) += a$        ENDIF      ENDWHILE      CLOSE #F%      = N% 


Re: Extracting a file list type (modification)
Post by michael on Dec 9th, 2017, 02:14am

Quote:
The code has been adapted from the FNdirscan function in SDLIDE.bbc, which is of course freely available for anybody to use as a source of code ideas.


I have looked over SDLIDE code and have thought about experimenting with the code. Would be nice to add a few custom built in commands if I could. One day I may try.

Thanks for that, I will see how I can adapt this to a future tool for cross platform.
Re: Extracting a file list type *and data manage
Post by michael on Dec 10th, 2017, 9:58pm

After a bit of research I got this example working. So temporary array can be created within a FN

And with this, technically I can redefine its size each time if I wanted to create a variable that holds a passed value to the array

This is part of the file management tool I am trying to design (trying to make it customizable and simple)

Code:
      REM CREATE a temporary array within a PROC or FN example      PROCtest      END      DEFPROCtest      LOCAL items():REM create a variable label and identify it as an array      DIM items(45):REM now give it a dimension      FOR x=0 TO 45        items(x)=RND(4000)      NEXT x      FOR x=0 TO 45:REM separating this so it shows a stored example and not realtime assigned example        PRINT items(x)      NEXT x      ENDPROC 




HA HA!! HERE IS THE GOOD STUFF !! PRIVATE ARRAYS!!

Code:
      REM CREATE a stored array within a PROC or FN example      PROCtest(0)      WAIT 200      PRINT "******* WHAT? I NEED THOSE RESULTS AGAIN  "      PROCtest(1):REM should reprint stored info      END      DEFPROCtest(n%)      ON ERROR LOCAL RESTORE LOCAL :  ERROR ERR, REPORT$      PRIVATE items():REM create a variable label and identify it as an array      DIM items(45):REM now give it a dimension      IF n%=0 THEN        FOR x=0 TO 45          items(x)=RND(4000)        NEXT x      ENDIF      FOR x=0 TO 45        PRINT items(x)      NEXT x      ENDPROC 


Isn't this exciting ?