I want to count files in one directory. (it can be ?00,000 files)
(in this case, no subdirectories, but the files can be on a network drive)
Then I saw - maybe a faster (and better?) method Joel Lipman.Com - (from 2013)
But this doesn't work for me (I don't know why)
Code: Select all
UserFolder:="C:"
-- to return file count in a folder
ItemCount := ComObjCreate("Shell.Application").NameSpace(UserFolder).Items.Count
FileCount := ComObjCreate("Scripting.FileSystemObject").GetFolder(UserFolder).Files.Count
FolderCount := ItemCount - FileCount
-- quick if looking at one directory.
-- just as slow if looping for subdirectories:
Loop, %UserFolder%\*.*, 1, 1
{
ThisFolder := RegExReplace( A_LoopFileFullPath, "\\$" )
ItemCount := ComObjCreate("Shell.Application").NameSpace(ThisFolder).Items.Count
FileCount := ComObjCreate("Scripting.FileSystemObject").GetFolder(ThisFolder).Files.Count
FolderCount := ItemCount - FileCount
TotalFileCount += FileCount
TotalFolderCount += FolderCount
}
Maybe there are even better ways to count files in a directory today?