> /// <summary>
> /// 移动Excel文件到指定位置
> /// </summary>
> /// <param name="oldPath">原文件位置+文件名(例如E:\TEST\1.txt)</param>
> /// <param name="newPath">移动文件位置+文件名(例如E:\TEST\File\1.txt)</param>
> /// <param name="path">移动文件夹位置(例如E:\TEST\File)</param>>
> public static void MoveServiceByExcel(string oldPath, string newPath, string path)
> {
> try
> {
> //判断移动的文件夹是否存在,不存在则创建
> if (Directory.Exists(path))
> {
> //先删除再移动
> File.Delete(newPath);
> File.Move(oldPath, newPath);
> Console.WriteLine(oldPath + "文件成功移动到" + newPath);
> }
> else
> {
> Directory.CreateDirectory(path);
> File.Move(oldPath, newPath);
> Console.WriteLine(oldPath + "文件成功移动到" + newPath);
> }
> }
> catch (Exception ex)
> {
> Console.WriteLine("文件移动失败:" + ex.ToString());
> }
> }
C#实现移动文件到指定文件夹
于 2023-01-12 14:03:10 首次发布