using System;
using System.IO;
public class FileMove
{
public FileMove()
{
// TODO:
}
// copy all file(*.png) in folder src to dest
private static void copyFiles(string srcFolder, string destFolder)
{
DirectoryInfo directoryInfo = new DirectoryInfo(srcFolder);
FileInfo[] files = directoryInfo.GetFiles();
foreach (FileInfo file in files) // Directory.GetFiles(srcFolder)
{
if (file.Extension == ".jpg")
{
file.CopyTo(Path.Combine(destFolder, file.Name)); //复制 ,剪切的话file.MoveTo();
}
// will move all files without if stmt
//file.MoveTo(Path.Combine(destFolder, file.Name));
}
}
// test demo
static void Main(string[] args)
{
string src = "E:\\test\\src";
string dest = "E:\\test\\dest";
copyFiles(src, dest); // src -> dest
Console.WriteLine("image copy finished!");
Console.ReadLine();
}
}
C#将文件中的图片复制到另一个文件中
最新推荐文章于 2024-06-16 22:05:07 发布