检测文件 [英] Detecting files
本文介绍了检测文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,有什么方法可以检测文件夹中的文件吗?
像这样:
Hello, is there any way to detect files in a folder?
like this:
if files in Directory.GetFiles(@"C:\TRASH")
我找不到办法.
谢谢您.
I can''t find a way to do this.
Thank you
推荐答案
为此使用FileSystemWatcher类会更高效.这将通知是否有更改.您可以在此处在代码项目上进行搜索以找到一些很好的示例.
http://msdn.microsoft.com/en-us/library/system.io. filesystemwatcher.aspx [ ^ ]
祝您好运!
It would be more efficient to use the FileSystemWatcher Class for that. That will notify if there are changes. You can do a search here on code project for some good examples.
http://msdn.microsoft.com/en-us/library/system.io.filesystemwatcher.aspx[^]
Good luck!
如果通过检测,您的意思是看看是否只有一次文件,请使用System.IO.否则,要监视文件夹,请按照说明使用FileSystemWatcher类.它有一些非常好的事件
if by detect, you mean see if there is any file just once, use System.IO. Otherwise, to monitor a folder, use FileSystemWatcher class as stated. It has some very nice events
如果只需要检测该目录中是否有文件,请使用以下命令:
In case you only need to detect if there are files in that directory use this:
string directory = @"C:\TRASH";
bool thereAreSomeFiles = Directory.Exists(directory) &&
Directory.GetFiles(directory);
此后,如果目录存在并且其中有任何文件,则ThereAreSomeFiles将为true.
干杯
曼弗雷德(Manfred)
After that thereAreSomeFiles will be true if the directory exists and there are any files in it.
Cheers
Manfred
这篇关于检测文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文