File類和FileInfo類來演示如何移動檔案
阿新 • • 發佈:2018-12-13
void MoveFile1() { string fileToMove = @"c:\temp\New Text Document.txt"; string fileNewDestination = @"c:\temp\test.txt"; if (File.Exists(fileToMove) && !File.Exists(fileNewDestination)) { File.Move(fileToMove, fileNewDestination); } } void MoveFile2() { string fileToMove = @"c:\temp\New Text Document.txt"; string fileNewDestination = @"c:\temp\test.txt"; FileInfo file = new FileInfo(fileToMove); if (file.Exists) { file.MoveTo(fileNewDestination); } }