C# 文件操作 之 删除、复制、转移多个文件[转]
string[] format = { "*.jpg", "*.doc", "*.exe", "*.pdf", "*.xls" }; # 文件流操作 之 删除、复制、转移多个文件 /// <summary> /// 删除文件夹下面所有图片 /// </summary> /// <param name="oldpngPath">待删除文件路径</param> /// <param name="newpngPath">删除到的新目录</param> /// <param name="geshi">操作文件的格式 例如:*.png、*.xml</param> public void deleteAll(string delpath, string format ) { string[] files = Directory.GetFiles(delpath, format[0]); foreach (string file in files) { File.Delete(file); } } /// <summary> /// 复制文件夹下面所有图片 /// </summary> /// <param name="oldpngPath">待复制文件路径</param> /// <param name="newpngPath">复制到的新目录</param> /// <param name="geshi">操作文件的格式 例如:*.png、*.xml</param> public void copyALl(string oldpngPath, string newpngPath, string format ) { string[] files = Directory.GetFiles(oldpngPath, format[0]); foreach (string file in files) { string otherFile = Path.Combine(oldpngPath, Path.GetFileName(file)); File.Copy(file, newpngPath + "\\" + Path.GetFileName(file)); } } /// <summary> /// 移动文件夹下的所有文件 /// </summary> /// <param name="olderpath">待移动的文件目录</param> /// <param name="topath">新目录</param> public void moveAll(string olderpath, string topath) { string[] files = Directory.GetFiles(delpath, format[0]); foreach (string file in files) { File.Move(file, topath); //移动文件 } }