Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
NUMBER OF FILES IN A DIRECTORY
Message
 
 
To
11/03/2000 02:16:49
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00344120
Message ID:
00344562
Views:
34
>>True but we would be remiss if we did not offer it purely for thoroughness reasons *g*.
>
>Read the whole thing: Thread#314887

It's good reading. Thanks.

However, the interesting point of the thread to me was the problem with large numbers of files in directories. Now I don't have 13000+ in any of my directories but my System32 directory has 1571 files and directories. The following code showed FSO to be about 1.5x faster than ADIR():
for lyy = 1 to 10
? "Round " + transform(lyy)
t1=seconds()
for lxx = 1 to 20
oFS = createobject("scripting.FileSystemObject")
oFolder = oFS.GetFolder("d:\winnt\system32\")
With oFolder
n = .Files.Count + .Subfolders.Count
Endwith
oFolder = .NULL.
oFS = .NULL.
endfor
t2 = seconds() - t1
? n
*local array lafiles[1]
t3 = seconds()
for lxx = 1 to 20
n = adir(lafiles,"d:\winnt\system32\*.*","DHS") - 2
* release lafiles
endfor
t4 = seconds() - t3
?n
? transform(t2),transform(t4)
endfor

If you uncomment the 'release lafiles' to perform cleanup after each pass, then FSO becomes over 4x faster.

Since we were dealing with counts only, IMO FSO would be the way to go. There is no added overhead in building an array just to get the number of files in a directory. If we wanted to perform some other task (e.g. populating a control with file names) then FSO probably would not be the way to go because of the overhead of COM.

In this instance, the overhead of an array far outweighs the overhead of COM.
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Reply
Map
View

Click here to load this message in the networking platform