1. 程式人生 > >File類和FileInfo類來演示如何移動檔案

File類和FileInfo類來演示如何移動檔案

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);          }       }