First, you don't need the the
If TypeOf fsinfo Is System.Io.FileInfo
becuase you're getting nothing but FileInfo objects from the
GetFileInfos
call. I'm all for defensive coding but that's overkill.
Next, You don't need to put the namespaces ahead of every class, like
System.Io.Path.Combine
. If you put
Imports
statements at the top of your file, you don't need to type all that stuff. It just becomes:
Include System.Io
.
.
If Not Directory.Exists(...)
Dim destFileName As String = Path.Combine(...)
Oh, and putting the old Hungarian type prefix on everything is so 1990's. Stop it. Use more descriptive variable names, like
destFilepath
and
sourceFilepath
. That garbage was only used when the compiler didn't do type checking for you, such as VBScript. VB.NET is fully type safe. What you're doing is redundant.
Now, on to the problem at hand...
All you have to do is get a FileInfo object for the soruce file and the destination file, then compare the
LastWriteTime
properties of both. They're different, copy the file. If not, move on to the next file.