BBC BASIC
« Extracting a file list type (+data management »

Welcome Guest. Please Login or Register.
Dec 12th, 2017, 1:04pm


Cross-platform BBC BASIC (Win32, Linux x86, Android, Mac OS-X, Raspberry Pi)

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Extracting a file list type (+data management  (Read 82 times)
michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 125
xx Extracting a file list type (+data management
« Thread started 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


 
« Last Edit: Dec 10th, 2017, 10:05pm by michael » User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Richard Russell
Administrator
ImageImageImageImageImage


member is offline

Avatar




Homepage PM


Posts: 646
xx Re: Extracting a file list type (modification)
« Reply #1 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% 

« Last Edit: Dec 8th, 2017, 2:03pm by Richard Russell » User IP Logged

michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 125
xx Re: Extracting a file list type (modification)
« Reply #2 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.
User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
michael
Full Member
ImageImageImage


member is offline

Avatar




PM


Posts: 125
xx Re: Extracting a file list type *and data manage
« Reply #3 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 ?
« Last Edit: Dec 10th, 2017, 11:15pm by michael » User IP Logged

I like reinventing the wheel, but for now I will work on tools for D3D
Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

Donate $6.99 for 50,000 Ad-Free Pageviews!


This forum powered for FREE by Conforums ©
Sign up for your own Free Message Board today!
Terms of Service | Privacy Policy | Conforums Support | Parental Controls