Author |
Topic: How can I read the filenames from a folder (Read 760 times) |
|
Danny72
New Member
member is offline


Posts: 20
|
 |
How can I read the filenames from a folder
« Thread started on: Mar 19th, 2010, 11:01am » |
|
Hello Everyone
Could someone let me know how I can read (into some kind of variables) the filenames from a particular folder in Windows.
Many thanks
Danny
|
|
Logged
|
|
|
|
Malcolm
Guest
|
 |
Re: How can I read the filenames from a folder
« Reply #1 on: Mar 19th, 2010, 3:00pm » |
|
Google "MSDN findfirstfile"
or search the group files for FindFirstFile or FindNextFile. That's the API's that you need.
|
|
Logged
|
|
|
|
Danny72
New Member
member is offline


Posts: 20
|
 |
Re: How can I read the filenames from a folder
« Reply #3 on: Mar 21st, 2010, 7:19pm » |
|
Thanks for the information.
Danny
|
|
Logged
|
|
|
|
Danny72
New Member
member is offline


Posts: 20
|
 |
unable to get the code working
« Reply #4 on: Mar 22nd, 2010, 5:32pm » |
|
Hi
Running this results in the error Not in a FN or PROC Could someone let me know what I need to do to run this. I just want to be able to read filenames into a string variable. Thanks.
LOCAL dir%, sh%, res% DIM dir% LOCAL 317 SYS "FindFirstFile", "*", dir% TO sh% IF sh% <> -1 THEN REPEAT PRINT $$(dir%+44) SYS "FindNextFile", sh%, dir% TO res% UNTIL res% = 0 SYS "FindClose", sh% ENDIF ENDPROC
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: unable to get the code working
« Reply #5 on: Mar 23rd, 2010, 09:28am » |
|
on Mar 22nd, 2010, 5:32pm, Danny72 wrote:Running this results in the error Not in a FN or PROC |
|
The code has evidently been lifted from a PROC, because of the LOCAL, DIM...LOCAL and ENDPROC:
Code: LOCAL dir%, sh%, res%
DIM dir% LOCAL 317
...
ENDPROC Therefore the easiest thing to do would be to use it in a PROC or FN yourself.
Trying to run the code outside a PROC or FN would risk a memory leak, because of the DIM. You could change the memory block at dir% to a structure; that would make the code more elegant and avoid the memory leak, but it's a lot of work when the alternative of putting it in a PROC or FN is so much easier.
Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: How can I read the filenames from a folder
« Reply #7 on: Mar 23rd, 2010, 3:26pm » |
|
I have written a Wiki article listing a function FNfiles which reads the contents of a disk directory into a string array (not dissimilar to Liberty Basic's FILES statement):
http://bb4w.wikispaces.com/Listing+the+contents+of+a+directory
This may be useful when you want to avoid using the Windows API directly.
Richard.
|
|
Logged
|
|
|
|
Danny72
New Member
member is offline


Posts: 20
|
 |
Re: How can I read the filenames from a folder
« Reply #8 on: Mar 23rd, 2010, 4:19pm » |
|
Thanks for the code.
Danny
|
|
Logged
|
|
|
|
|