1

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

  • More information, please. Do you want to list the contents of a particular directory, or iterate through a directory tree, or list the contents of an entire disk? – Harry Johnston May 25 '12 at 03:28
  • http://stackoverflow.com/questions/7421440/how-can-i-detect-only-deleted-changed-and-created-files-on-a-volume/7459109#7459109 – Harry Johnston May 26 '12 at 05:46
  • From what you've said about Defraggler, it sounds as if it might be gathering information ahead of time and giving it to you from a cache. But if you want the entire contents of the drive, the USN is pretty fast, in the order of 6000-20000 records per second even on an older machine. Sample code at the link in my previous comment. – Harry Johnston May 26 '12 at 05:47

2 Answers2

0

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.

Indinfer
  • 532
  • 5
  • 4
-1

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

Radagast
  • 1,026
  • 6
  • 15
  • 21
  • Powershell is a language, not an API. – Harry Johnston May 25 '12 at 03:27
  • Yes my problem is, such way would take a looong time to complete for the entire drive. Defraggler (a defrag program) can do this in under 10 seconds while my drive has 300k+ files. Other program like Everything (search file utility) is also fast although not as fast as defraggler, the author used NTFS USN Journal to achieve this. – randadinata May 25 '12 at 05:37
  • While powershell may not be an API, it is still a vialble solution to the problem that is now included with windows. if the script is properly written it could easily recurse through the entire hard drive and give the desired end results, and without having to depend upon a third party application – Radagast May 25 '12 at 12:19
  • I'm trying to make a software that mimic Treesize, calculate each directory size. So Powershell won't do at the moment. Because powershell is obviously slow if the drive have hundreds of thousands of files with deep directory trees. Beside if simple listing of my drive is what i need i would just probably use cmd.exe one liner, "dir c:\ /s /a > filelist.txt" works since the day of MS-DOS to Windows 7. You don't need Powershell to do that. – randadinata May 25 '12 at 15:06
  • @Radagast: the OP doesn't need either a "third party application" or Powershell. He's clearly writing his *own* application, hence the comment about FindFirstFile/FindNextFile, and the fact that he posted the question on a programming site. – Harry Johnston May 26 '12 at 05:44