2013-03-12 64 views
0

我已經寫了一個數據分類器,它向它正在寫入的文件寫出一個.build擴展名,所以在向特定文件寫入數據時沒有任何東西試圖解除它。在VB.NET中重命名文件擴展名

最後,我想在程序關閉之前用.build擴展名重命名爲.dat。

For Each f In outputFiles 

     For Each r In TrailerRecords 

      ' Set the bill count variable 
      If r.VariableField Then 
       r.Fields(1) = String.Format("{0:000000}", f.Value) 
      End If 

      ' Write the trailer record to the output file 
      File.AppendAllText(f.Key, r.ToString() & vbLf) 
     Next 

     ' Rename all.build files to .dat 

NEEDS TO GO HERE 

     ' Copy each output file to the backup directory 
     File.Copy(f.Key, Path.Combine(backupFolder, Path.GetFileName(f.Key)), True) 
    Next 
End Sub 
+0

你讀過http://stackoverflow.com/questions/10784613/how-to-rename-file-in-vb-net?它看起來會解決你的問題。 – SolarBear 2013-03-12 13:01:30

回答

4

獲取文件,並將其重命名:

Dim auxFile as String 
Dim files() As String = IO.Directory.GetFiles(myFolderPath, "*.build") 

For Each sFile As String In files 
    auxFile = IO.Path.GetFileNameWithoutExtension(sFile) & ".dat" 
    My.Computer.FileSystem.RenameFile(sFile, auxFile) 
Next 

您可以使用File.Copy()與覆蓋屬性True代替。

看看MSDN文檔:

+0

非常感謝SysDragon,這正是我所需要的,必須在應用程序中找到正確的位置來玩一下,但我得到了這些。 – Gerry85 2013-03-12 14:34:51