I am trying to loop through a local directory and print out the name of all subdirectories and files within. The start path of the search is provided, and it can be possible that there are nested directories.
The start directory looks like:
and for example, within the appendix directory, we have:
And the directory nesting could go on as many times, but for this example these two sub directories a1 and a2 only contain some .txt files.
I have seen some other similar question like Get list Of Files in a Directory in Foxpro but I do not seem to get anything correct with what is shown here. If this question and answer does indeed apply directly to my question maybe someone can help clarify how I can utilize this answer.
Right now I just want to print out the names of all content (directories and files) as the loop goes through each subdirectory until it has gone through all items inside the initial starting directory. It would also be nice to print out other information like the last modified date of each item as well. The output with just the file names would look something like:
appendix
a1
a1text.txt
a2
a2text.txt
aTotal.txt
index (nothing inside index so moving on)
names
allnames.txt
Thanks in advance for any help.


When you run the following sample code, it evaluates all File items in the parametrized start folder, and when it finds a sub-Folder, there it starts itself recursively to do the same again.
As for your comments asking for additional explanations: The local F1 Help file that ships with
visual-foxpro, i.e. its community version content, is also available online:vfphelp-adir
vfphelp-directory
vfphelp-addbs
Don't hesitate to comment on additional aspects.
Edited: As for the OP's comment:
The dots get into the first ADir() result elements when its 3rd parameter is "D"(irectory). IDE Command Window example:
That behavior is not documented AFAIK, might perhaps have been an ancient feature related to the DOS/FoxPro
CDcommand