public static class MyFile
{
/// <summary>
/// 创建文件夹
/// </summary>
public static string CreateFolder(string argPath)
{
string returnStr = "";
try
{
if (System.IO.Directory.Exists(argPath))
{
returnStr = "该文件夹已经存在";
return "2";
}
else
{
System.IO.DirectoryInfo dirinfo = System.IO.Directory.CreateDirectory(argPath);
returnStr = "1";
}
}
catch (Exception ee)
{
returnStr = "0";
}
return returnStr;
}
#region 获取一个文件夹下的所有文件夹里的文件
/// <summary>
/// 获取一个文件夹下的所有文件夹里的文件
/// </summary>
/// <param name="dirs"></param>
/// <param name="filesList"></param>
private static void GetAllDirsFiles(DirectoryInfo[] dirs, Dictionary<string, DateTime> filesList)
{
foreach (DirectoryInfo dir in dirs)
{
foreach (FileInfo file in dir.GetFiles("*.*"))
{
filesList.Add(file.FullName, file.LastWriteTime);
}
GetAllDirsFiles(dir.GetDirectories(), filesList);
}
}
#endregion
/// <summary>
/// 获取某文件夹下的某种文件
/// </summary>
/// <param name="path"></param>
/// <param name="filesList"></param>
public static void GetOneTypeFiles(string path, IDictionary<string, DateTime> filesList, string type)
{
DirectoryInfo folder = new DirectoryInfo(path);
foreach (FileInfo file in folder.GetFiles("*." + type + ""))
{
filesList.Add(file.FullName, file.LastWriteTime);
}
}
}