How to check if file already exists in the folder
I am trying to copy some files to folder. I am using the following statement to check if the source fie exists
If My.Computer.FileSystem.FileExists(fileToCopy) Then
But I donot know how to check if file exists in the folder before copying. Please advise.
Thanks and best regards, 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