我正在尝试将一些文件复制到文件夹中。我使用以下语句检查源文件是否存在:
如果 My.Computer.FileSystem.FileExists(fileToCopy) Then
但是我不知道如何在复制之前检查文件是否存在于文件夹中。请给予建议。
谢谢并致以最好的问候, Furqan
我正在尝试将一些文件复制到文件夹中。我使用以下语句检查源文件是否存在:
如果 My.Computer.FileSystem.FileExists(fileToCopy) Then
但是我不知道如何在复制之前检查文件是否存在于文件夹中。请给予建议。
谢谢并致以最好的问候, Furqan
Dim SourcePath As String = "c:\SomeFolder\SomeFileYouWantToCopy.txt" 'This is just an example string and could be anything, it maps to fileToCopy in your code.
Dim SaveDirectory As string = "c:\DestinationFolder"
Dim Filename As String = System.IO.Path.GetFileName(SourcePath) 'get the filename of the original file without the directory on it
Dim SavePath As String = System.IO.Path.Combine(SaveDirectory, Filename) 'combines the saveDirectory and the filename to get a fully qualified path.
If System.IO.File.Exists(SavePath) Then
'The file exists
Else
'the file doesn't exist
End If
Dim FileName = "newfile.xml" ' The Name of file with its Extension Example A.txt or A.xml
Dim FilePath ="C:\MyFolderName" & "\" & FileName 'First Name of Directory and Then Name of Folder if it exists and then attach the name of file you want to search.
If System.IO.File.Exists(FilePath) Then
MsgBox("The file exists")
Else
MsgBox("the file doesn't exist")
End If
system.io.path
类来操作路径,就像我的示例所示。如果这确实是您的意思,请告诉我们。 - Bradley Uffner