BBC BASIC for Windows
« How can I read the filenames from a folder »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:49pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: How can I read the filenames from a folder  (Read 760 times)
Danny72
New Member
Image


member is offline

Avatar




PM


Posts: 20
xx 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
User IP Logged

Malcolm
Guest
xx 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.



User IP Logged

Malcolm
Guest
xx Re: How can I read the filenames from a folder
« Reply #2 on: Mar 19th, 2010, 3:06pm »

Or here it is already done for you!

http://bb4w.wikispaces.com/Scanning+a+Directory+%28Reading+Directory+Entries%29
User IP Logged

Danny72
New Member
Image


member is offline

Avatar




PM


Posts: 20
xx Re: How can I read the filenames from a folder
« Reply #3 on: Mar 21st, 2010, 7:19pm »

Thanks for the information.

Danny
User IP Logged

Danny72
New Member
Image


member is offline

Avatar




PM


Posts: 20
xx 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
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx Re: How can I read the filenames from a folder
« Reply #6 on: Mar 23rd, 2010, 09:43am »

on Mar 19th, 2010, 3:06pm, Guest-Malcolm wrote:
Or here it is already done for you!
http://bb4w.wikispaces.com/Scanning+a+Directory+%28Reading+Directory+Entries%29

It's in the main help documentation too:

http://www.bbcbasic.co.uk/bbcwin/manual/bbcwine.html#dirlist

Richard.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

Danny72
New Member
Image


member is offline

Avatar




PM


Posts: 20
xx Re: How can I read the filenames from a folder
« Reply #8 on: Mar 23rd, 2010, 4:19pm »

Thanks for the code.

Danny
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls