概述
/// <summary>
/// 图片文件迁移
/// </summary>
private void MoveFile(string Frompath, string directoryPath)
{
string[] picList = Directory.GetFiles(Frompath, "*.jpg"); //图片
string[] txtList = Directory.GetFiles(Frompath, "*.txt"); //文本文件
string[] pdfList = Directory.GetFiles(Frompath, "*.pdf"); //PDF文件
foreach (string f in picList)
{
//取得文件名.
string fName = f.Substring(Frompath.Length + 1);
File.Copy(Path.Combine(Frompath, fName), Path.Combine(directoryPath, fName), true);
}
foreach (string f in txtList)
{
string fName = f.Substring(Frompath.Length + 1);
try
{
File.Copy(Path.Combine(Frompath, fName), Path.Combine(directoryPath, fName));
}
// 捕捉异常.
catch (IOException copyError)
{
MessageBox.Show(copyError.Message);
}
}
foreach (string f in pdfList)
{
string fName = f.Substring(Frompath.Length + 1);
try
{
File.Copy(System.IO.Path.Combine(Frompath, fName), System.IO.Path.Combine(directoryPath, fName));
}
catch (IOException copyError)
{
MessageBox.Show(copyError.Message);
return;
}
}
//删除原始文件夹里的文件
foreach (string f in txtList)
{
File.Delete(f);
}
foreach (string f in picList)
{
File.Delete(f);
}
foreach (string f in pdfList)
{
File.Delete(f);
}
}
转载:https://www.cnblogs.com/Alisa-study/p/5803597.html
最后
以上就是寒冷过客为你收集整理的C# 文件迁移的全部内容,希望文章能够帮你解决C# 文件迁移所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复