Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Could not figure out exactly what this code does
Message
From
03/06/2009 12:41:21
Dragan Nedeljkovich (Online)
Now officially retired
Zrenjanin, Serbia
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP1
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01403230
Message ID:
01403429
Views:
58
This message has been marked as a message which has helped to the initial question of the thread.
>>>>Dunno - skipping the normal files ?
>>>
>>>So, what outweighs? Longer loop or a danger of switching path?
>>
>>You don't need to switch paths at all. As Hank said, it was a limitation on aDir() two geological eras ago; nowadays you just give it a full path as a filespec. So
>>
>>
procedure recurseDir(tcDir)
>>local i, n, laDirs[1]
>>n=adir(laDirs, forcepath("*.*", tcdir, "D"))
>>for i=1 to n
>>   lcDir=forcepath(laDirs[i,1], tcdir)
>>   if ladirs[i,5]="D" && plus other checks that it's really a directory we need
>>* this is it, do with it what we need and recurse into it:
>>      RecurseDir(lcDir)
>>   else
>>* it's not, do something else or nothing at all
>>  endif
>>endfor
>
>You missed the point, Dragan.
>
>If you're in the directory and run
>
>n = adir(laDir, "",'D")
>
>you don't get files listed in your array. Hence was my question.

This was about switching directories - note that there's no Set Default anywhere in this code. You can use aDir() to recurse wherever you want, without moving. The resulting array contains no paths, but the 2nd parameter can contain a path, and it will be respected. But you get files too and need to skip them. BTW, if ladirs[i,5]="D" is wrong, it should be if "D" $ ladirs[i,5].

So just to see what you're talking about, I've tried all of these:

adir(a, "fullpath\", "D") - gives just . and ..
adir(a, "fullpath", "D") - gives just fullpath
adir(a, "fullpath\*.", "D") - gives anything that has no extension, file or not
adir(a, "fullpath\*.*", "D") - gives all directories and files
adir(a, "", "D") gives subdirectories in current directory (with extension or not)

My preference is to filter out the directories and never change current directory. If there's anything in your code that errors out for any reason, you can't be sure that your cleanup code will Set Default To (lcWhereWeStartedFrom). Your app may not find its pieces if set("path") wasn't recomposed to contain absolute paths. Files you may create after that may end anywhere or nowhere. While fixing this, you may create a prg with the same name as one in another directory and next time you will have the pleasure of fixing one while the other actually runs, etc etc. Which is why I prefer my app to live a sedentary life, no travel.

back to same old

the first online autobiography, unfinished by design
What, me reckless? I'm full of recks!
Balkans, eh? Count them.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform