2014-10-02 96 views
-3

我需要檢查文件是否存在。如果文件不存在,那麼我需要一個文件複製到另一個如何將一個文件複製到另一個vb.net 2008

我厭倦了這樣的

昏暗roming作爲字符串 roming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)

如果不是文件。存在(roming & 「\」 & Environment.UserName.ToString & CONFIG_FILE)然後

我需要的默認文件複製到roming路徑文件

默認的文件是:My.Application.Info.DirectoryPath &配置文件中

+0

你有沒有想過,當一個文件將存在於您檢查其存在的時間,但會被您執行相關操作時被刪除的情況嗎? – Neolisk 2014-10-02 19:19:20

回答

0

確定這裏是代碼:

Dim roming As String 
roming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) 
If Not File.Exists(roming & "\" & Environment.UserName.ToString & CONFIG_FILE) Then 
IO.File.Copy(My.Application.Info.DirectoryPath & CONFIG-FILE , roming & "\" & Environment.UserName.ToString & CONFIG_FILE) 
End If 
0

不知道你正在嘗試做的,但這裏是一個簡單的例子:

Dim OriginalFilePath As String = "Put here you file path" 
Dim NewFilePath As String = "Put here you new file, that you want to copy into it" 
' Checks if the original file exists in the file system of the computer. 
If My.Computer.FileSystem.FileExists(OriginalFilePath) = True Then 
    ' Creates a new file, and copy all the content of the original file, into it 
    System.IO.File.Copy(OriginalFilePath, NewFilePath) 
End If 

欲瞭解更多信息,採取看看here

相關問題