我想将一些文件复制到文件夹.我使用以下语句来检查源是否存在
If My.Computer.FileSystem.FileExists(fileToCopy) Then
但我不知道在复制之前如何检查文件夹中是否存在文件.请指教.
谢谢和最好的问候,Furqan
Bra*_*ner 52
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
Run Code Online (Sandbox Code Playgroud)