2014-12-06 59 views
0

情況是這樣的: 我使用字符串格式一樣創建一個新的文件名:如何在C#中用字符串格式重命名文件?

string newFileName = string.Format("{0}/{1}/{2}/{3}.txt", FileInfo.Year, 
      FileInfo.Month, FileInfo.Day, FileInfo.Time); 

和我有另一個(舊)用文件的路徑:string path = @"C:\Users\Public\fileName.txt" 我想改變或移動老 - >新的。怎麼做?是否有可能改變新的路徑? 有沒有人可以幫助我。在此先感謝

+5

'System.IO.File.Move'。 – Mephy 2014-12-06 03:17:57

+0

謝謝。我會照顧。 – Steve 2014-12-06 03:40:40

回答

0
string path = @"C:\Users\Public\fileName.txt"; 

if (File.Exists(path)) 
      File.Move(path, "DestinationFilePath"); 
+0

而不僅僅是發佈代碼,如果你包含一個關於它如何解決問題的簡單解釋,那麼對他人更有幫助。 – Leigh 2014-12-06 06:08:39

相關問題