【实例代码】Console.WriteLine("输入文件所在文件夹路径(可拖入),按确认键执行"); string path = Console.ReadLine();
DirectoryInfo RootFolder = new DirectoryInfo(@path);
if (!RootFolder.Exists)
{
Console.Write("不存在此文件夹");
}
FileInfo[] fileInfos = RootFolder.GetFiles();
foreach (FileInfo file in fileInfos)
{
if (file.Extension.ToLower() != ".mark" && file.Extension.ToLower() != ".pdf") continue;
try
{
File.Copy(file.FullName, RootFolder "\\" file.Name.Split('.')[0] "\\" file.Name, true);
//if (File.Exists(RootFolder "\\" file.Name.Split('.')[0] "\\" file.Name))
//{
// File.Delete(RootFolder "\\" file.Name.Split('.')[0] "\\" file.Name);
//}
//File.Move(file.FullName, RootFolder "\\" file.Name.Split('.')[0] "\\" file.Name);
Console.Write("移动" file.Name);
}
catch { Console.Write("移动" file.Name "出错"); }
//RootFolder "\\" file.Name.Split('.')[0]
}
评论