2014-10-02 102 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

相关问题