Author |
Topic: Extracting a file list type (modification) (Read 297 times) |
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Extracting a file list type (modification)
« Thread started on: Dec 6th, 2017, 02:53am » |
|
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
|
|
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
DDRM
Administrator
member is offline


Gender: 
Posts: 321
|
 |
Re: Extracting a file list type (modification)
« Reply #1 on: Dec 7th, 2017, 08:44am » |
|
Hi Michael,
Thanks- that's some useful code.
Here is an amended version, to address a few points, some of which relate to the fact that you have made a procedure, but it relies internally on global names (such as the name of the array), and also sets a variable (f$) which isn't declared as local, so could mess up the main program.
I thought it would be nice to have the routine report the number of files it had found, so I've changed it to a function. That simplifies the process of listing (or indeed processing) the resulting array data.
I've also passed the array to put the data in as a parameter, so that the procedure doesn't need to know what the host program thinks it is called, making it more flexible and re-usable. I've given it a different name so that that is obvious. It's OK to use the same name, but potentially confusing...
You can amend the searchstring in FindFirstFile (and implicitly in FindNextFile), which saves having to check separately for your extension, so I've implemented that, which allows me to simplify the function somewhat.
Note that the routine will only work in the currently selected directory: if you wanted to look elsewhere the programme would need to set that directory first (but that's what FindFirstFile does, so it's no criticism of your routine!).
Also note that "ext%" will cause problems for people using lower case keywords.
Best wishes,
D Code: DIM my_files$(500):REM holds current files.Make this as big as you think you will need
numfiles%=FNlistdirectory(".bbc",my_files$())
FOR x%=0 TO numfiles%-1
PRINT my_files$(x%)
NEXT x%
END
DEF FNlistdirectory(ext$,store$())
LOCAL filedata%, searchhandle%, res%,c%
DIM filedata% LOCAL 317
SYS "FindFirstFile", "*"+ext$, filedata% TO searchhandle%
IF searchhandle% <> -1 THEN
REPEAT
store$(c%)=$$(filedata%+44)
c%+=1
SYS "FindNextFile", searchhandle%, filedata% TO res%
UNTIL res% = 0
SYS "FindClose", searchhandle%
ENDIF
=c%
|
|
Logged
|
|
|
|
michael
Senior Member
member is offline


Posts: 335
|
 |
Re: Extracting a file list type (modification)
« Reply #2 on: Dec 7th, 2017, 1:47pm » |
|
Thanks for that.
I think I will need to make a scrolling bar that displays perhaps 20 at a time and the ability to select the file you want to work with or save over.
That shouldn't be hard to do.
|
|
Logged
|
I like making program generators and like reinventing the wheel
|
|
|
|