Page 1 of 1
Number of files in a folder?
Posted: Tue Oct 25, 2011 12:03 am
by Seymour Clufley
This is a ridiculously basic question and I'm sorry to ask it.
Is there a fast way to get the number of files in a directory, on Windows?
I had a look in PureArea and found
this but that simply loops through all the files with NextDirectoryEntry. Surely there's an API call or something which can get the number more quickly than that?
It doesn't need to check sub-directories.
Re: Number of files in a folder?
Posted: Tue Oct 25, 2011 12:54 am
by Shield
There is no other way, at least not as far as I know.
You have to iterate through the directory to count the files.
The main reason for that being the file system's access management.
In that folder there might be some files you're not allowed to see, so the operating system
has to check your access rights for every file.
Re: Number of files in a folder?
Posted: Thu Oct 27, 2011 12:16 am
by buddymatkona
For this kind of thing I usually use a script but you can still drive the action from PB.
http://www.purebasic.fr/english/viewtop ... fa185f6029
Re: Number of files in a folder?
Posted: Thu Oct 27, 2011 11:23 am
by MachineCode
Seymour Clufley wrote:I had a look in PureArea and found
this but that simply loops through all the files with NextDirectoryEntry
Actually, that's pretty fast (once you delete the recursion into subfolders of it).
Or maybe populate an (invisible) ExplorerListGadget() with your path and count its files:
Code: Select all
If OpenWindow(0,0,0,400,400,"",#PB_Window_SystemMenu)
ExplorerListGadget(0,0,0,400,400,"C:\Windows\",#PB_Explorer_NoFolders)
SetWindowTitle(0,Str(CountGadgetItems(0)-1))
Repeat : Until WaitWindowEvent()=#PB_Event_CloseWindow
EndIf