我需要检查文件是否存在。如果文件不存在,那么我需要将一个文件复制到另一个文件
我这样累了
Dim Roming As String roming = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
如果不是File.Exists(roming&“\”& Environment.UserName.ToString& CONFIG_FILE)那么
我需要将默认文件复制到roming path file
默认文件是:My.Application.Info.DirectoryPath& CONFIG-FILE
答案 0 :(得分: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。
答案 1 :(得分: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