Click here to Skip to main content
16,018,419 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

i want to take the count of files in a remote machine.i used these codes:

C#
1st method:System.IO.Directory.EnumerateFiles(path, "*.*", SearchOption.AllDirectories).Count();

2nd method:System.IO.Directory.GetFiles(path, "*.*", SearchOption.AllDirectories).Count();


using these am getting the file count,but its taking very much time.(eg:my remote machine containing more than 50000 records and its taking more than 3-4 minuts). i need a better solution through which i will get the count even more faster.

Please help

thanks,
Elizabath
Posted

1 solution

Try this:
C#
Directory.GetFiles("\\\\RemoteMachine\\ShareName").Length;



--Amit
 
Share this answer
 
Comments
Elizabath D 3-Jun-13 5:42am    
i already used this method,but its showing count as zero.
_Amy 3-Jun-13 5:44am    
Try this linq:
var fileCount = (from file in Directory.EnumerateFiles(path, "FileFormat", SearchOption.AllDirectories)
select file).Count();


And this[^] may help you also.
--Amit
Elizabath D 4-Jun-13 0:55am    
thanks..its working for me.but i want to know can i change linq and use something else because i want to run this in 2.0 framework also,which do not support linq.
_Amy 4-Jun-13 1:07am    
The see A Faster Directory Enumerator[^]. And let me know if you able to make search faster. :)
--Amit
_Amy 4-Jun-13 1:13am    
Also see a similar solution : Reporting Progress on Directory.GetFiles[^].

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900