Qbasicnews.com

Full Version: Getting files in a directory
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Alright i just started working on making a program that could save and load stuff. But I don't know how to print out and store the directory. kinda like a gui. Could somone tell me?
PyroKid,

You can do something like this to get the list of files:

Code:
DIM FileArray() AS String
DIM Counter     AS LONG
DIM WorkFile    AS STRING

WorkFile = DIR("*.*")   ' CHANGE FILE SPECS IF NEEDED
COUNTER = 0
DO WHILE LEN(WorkFile) <> 0
   Counter = Counter + 1
   REDIM PRESERVE FileArray(Counter) AS STRING  
   FileArray(Counter) = WorkFile
   WorkFile = DIR
LOOP
Definitely easier with a windows environment DIR.
FileArray(Counter) = WorkFile
must be
FileArray(Counter-1) = WorkFile

First arrayindex are 0 by default or not?

Joshy
Code:
DO WHILE LEN(WorkFile) <> 0
   REDIM PRESERVE FileArray(Counter+1) AS STRING  
   FileArray(Counter) = WorkFile
   Counter+=1
   WorkFile = DIR
LOOP
:

Code:
Option Dynamic
...
DO WHILE LEN(WorkFile) <> 0
   REDIM PRESERVE FileArray(Counter) AS STRING    
   FileArray(Counter) = WorkFile
   Counter = Counter + 1
   WorkFile = DIR
LOOP

Maybe this works better.
Hello Neo,
first counter is 0
and
redim preserve array(0) as type
is not the same as
redim preserve array(1) as type

or not ?
what for a fb version you are using and Win or Lin?

Joshy