日期:2014-05-17 浏览次数:20928 次
int fileNum = 0;
/// <summary>
/// 获取某目录下的所有文件(包括子目录下文件)的数量
/// </summary>
/// <param name="srcPath"></param>
/// <returns></returns>
public int GetFileNum(string srcPath)
{
try
{
string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
foreach (string file in fileList)
{
if (System.IO.Directory.Exists(file))
GetFileNum(file);
else
fileNum++;
}
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
return fileNum;
}
int count = 0;
public void GetFilesCount(string path)
{
//如果嵌套文件夹很多,可以开子线程去统计
count += System.IO.Directory.GetFiles(path).Length;
foreach (var folder in System.IO.Directory.GetDirectories(path))
{
&n