简体   繁体   English

如何在C#中获取远程计算机中文件的数量

[英]how to get count of files in a remote machine in c#

i want to take the count of files in a remote machine.i used these codes: 我想对远程计算机中的文件计数。我使用了以下代码:

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). 使用这些可以获取文件计数,但是却要花费很多时间。(例如:我的远程计算机包含超过50000条记录,并且花费了3-4分钟)。 i need a better solution through which i will get the count even more faster. 我需要一个更好的解决方案,通过该解决方案,我可以更快地获得计数。

Maybe you can use a .Net remoting method that would require ac# server on your remote machine (c# remoting is like rmi in java or RPC in C) you can find out more about c# remoting here http://msdn.microsoft.com/fr-fr/library/vstudio/72x4h507%28v=vs.100%29.aspx . 也许您可以使用需要远程计算机上的ac#服务器的.Net远程处理方法(c#远程处理就像Java中的rmi或C中的RPC),您可以在此处找到有关c#远程处理的更多信息http://msdn.microsoft.com /fr-fr/library/vstudio/72x4h507%28v=vs.100%29.aspx

I Hope it will help 希望对您有所帮助

Try Following 尝试以下

Directory.GetFiles("\\\\RemoteMachine\\ShareName").Length;

you may also try Linq 您也可以尝试Linq

var fileCount = (from file in Directory.EnumerateFiles(path, "file format", 
                 SearchOption.AllDirectories)
                 select file).Count();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM