检索根目录下所有文件
来源:百度知道 编辑:UC知道 时间:2024/05/29 11:57:01
文件检索出来后,放在FILELISTBOX里面
这里的参数folderPath为@"C:\"就表示搜索C盘根目录下所有文件。
private void PrintLines(string folderPath)
{
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo(folderPath);
foreach (System.IO.FileInfo file in dir.GetFiles())
{
FILELISTBOX.Items.Add(file.FullName);
}
foreach (System.IO.DirectoryInfo dirs in dir.GetDirectories())
{
PrintLines(dir.FullName);
}
}
我这个是计算文件或者文件夹大小。用递归。希望对你有帮助
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace FileSizeClass
{
public class FileSizeClass
{
string FilePath = ""; //文件或者文件路径
public double GetSize(string path)
{
double size = 0;
if (path == null || path.Trim() == "" || path.Length == 0)
{
return size;
}
FilePath = p