Howto quickly gather file list with path and size information?

611 Views Asked by At

FindFirst/FindNext is slow. I see program like Defraggler can gather this list quickly. What Windows API they use ?

2

There are 2 best solutions below

5
On

Not sure about Defraggler; however you could use powershell

If you are on a windows xp system you will have to download and install it

with powershell you can preform a simple query

for example:

$foo = Get-childItem -Path "c:\windows"

in powershell this will put all of the file names in the windows directory into an array called $foo

you can then go further and take the array and pipe it into a file

$foo >> c:\temp\test.txt

Example output:


    Mode        LastWrite Time         Length Name                                       
----                -------------     ------ ----      
d----         7/14/2009   1:32 AM            Web                                        
d----          5/9/2012   3:20 AM            winsxs                                     
-a---          2/3/2012   1:01 PM      16896 AsTaskSched.dll                            
-a---          4/6/2011  12:46 AM      32200 atiogl.xml                                 
-a---          2/3/2012  12:35 PM          0 ativpsrm.bin                               
-a---        11/20/2010  10:24 PM      71168 bfsvc.exe                                  
-a--s         5/24/2012  10:17 PM      67584 bootstat.dat                               
-a---         3/21/2012  11:58 PM       1908 diagerr.xml                                
-a---         3/21/2012  11:58 PM       1908 diagwrn.xml                                
-a---          5/4/2012   6:19 PM      28406 DirectX.log    

For more info on powershell checkout

http://technet.microsoft.com/en-us/library/bb978526.aspx

0
On

You are saying "FindFirst/FindNext" is slow. I think in terms of execution, _findfirst(), _findnext(), _findclose() #include <io.h> is as fast as it gets.

If you need very long path names, you need to use the Windows API version.

The Windows API is FindFirstFile(), FindNextFile(), and FindClose(), and the header file is #include <windows.h>.

The documentation for the Windows API tells you how to prepend "\?\" to the directory strings and get the maximum possible path length.

If you need more information than the C Library functions give you, then you need to use the Windows API FindFirstFileEx(), FindNextFileEx(), FindClose().

I have to refer you to the documentation for the details.

Simplest, C Library, _findfirst(): https://msdn.microsoft.com/en-us/library/zyzxfzac.aspx

More Info returned, Maximum path lengths, Windows API FindFirstFile(): https://msdn.microsoft.com/en-us/library/windows/desktop/aa364418(v=vs.85).aspx

Maximum Info returned, Maximum path lengths, Windows API FindFirstFileEx(): https://msdn.microsoft.com/en-us/library/windows/desktop/aa364419(v=vs.85).aspx

If the links are no longer valid, you probably can search something like "C Language _findfirst()", etc.