Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
"Find all files" routine.
#1
I'm trying to make a routine that will, at the very least, be able to retreive the amount of files within a folder, in addition to being able to identify each file individually. The part I'm having trouble with is the fact that this routine must search a folder, in addition to searching inside the additional folders inside that folder, and so on. The problem I am having is unintentional recursion, and having the routine get stuck in the same folder over and over. Can anyone -not necessarily in code, though that would be helpful too- explain to me how I should go about doing this? At the very least, with this routine, I would like to be able to have an array with each individual file, along with the amount of files discovered.
Reply
#2
First find all directories and sub dirs, then find all files in the list of directories.
Reply
#3
Here. If it doesn't work then I don't know. Last FB version I tried this on was .14 or .15 I think:

Code:
declare sub dirlist(lev,d$)
dirlist 0,"C:\":sleep
'the first argument is only to define the number of spaces printed before each entry.
'The second argument MUST include the ending "\" or the program will crash!
sub dirlist(lev,d$)
        chdir d$
        dim j as ulongint,stuff(1024) as string,isdir(1024) as byte
        f=freefile
        open pipe "dir /b /ad" for input as #f
        while not eof(f)
                j+=1
                input #f,stuff(j)
                isdir(j)=1
        wend
        close f
        open pipe "dir /b /a-d" for input as #f
        while not eof(f)
                j+=1
                input #f,stuff(j)
                isdir(j)=0
        wend
        close f
        for i=1 to j
                if stuff(i)<>"" then
                        print space$(2*lev)+stuff(i);
                        if isdir(i)=1 then print "\" else print ""
                        if isdir(i)=1 then
                                dirlist lev+1,d$+stuff(i)+"\"
                                chdir d$
                        end if
                end if
        next j
end sub
Reply
#4
I suggest you get onto the DOS command line, and do something like this to get all the files and sub-directories starting from an assumed directory name like \STARTDIR.

DIR \STARTDIR\*.*/S/B > TEMP

If the TEMP file looks like it contains all the stuff you need, and you'll be able to process it in your program, then do the same thing in your program, like so:

SHELL "DIR \STARTDIR\*.*/S/B > TEMP"

Then open the TEMP file and read in the stuff.

However, if the TEMP file doesn't quite have what you want, then from the DOS commandline, do:
DIR /?
Look at the options, and keep testing until you get what you want into the TEMP file.

Using the DIR is by far the simplest way to get what you want. Doing the directory recursion
yourself is a real nightmare.
*****
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)