要引入using System.IO;
1,判斷文件是否存在,如果存在刪除
if (File.Exists(Path.GetFullPath(positonPath)))
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? File.Delete(Path.GetFullPath(positonPath));
? ? ? ? ? ? ? ? }
2 .給文件重命名
? ? ? ? ? ? ?? FileInfo fileInfo = new FileInfo(fullpath);
? ? ? ? ? ? ? ? string newFileName = “123abc”;
? ? ? ? ? ? ? ? fileInfo.MoveTo(Path.Combine(fileInfo.DirectoryName, newFileName));