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

Answers


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

Need Your Help

memory management in nested blocks

objective-c memory-management objective-c-blocks

References to local variables (including ivars) inside blocks are automatically retained to make sure it remains valid throughout the execution of the block.

NullPointerException When Making an Animation

android animation nullpointerexception android-viewpager android-context

I have one really annoying problem in my android app and I just cant figure out what the problem is.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.