-
Dir function in VB.Net
I'm writing a simple program that will periodically move all files in one folder to a different folder. When is use the Dir(pathname) function, it always seems to ignore or skip the first file in the folder. If there is only 1 file in the folder, the program thinks the folder is empty. Can anyone tell me how to fix this?
Thanks
-
Can you post your code? It kind of sounds like a zero based array issue.
-
It's really simple. Here it is:
SourcePath = "c:\data1"
TargetPath = "P:\data\NewFiles"
ifile = Dir(SourcePath + "\*.*")
While ifile <> ""
ifile = Dir()
If ifile <> "" Then
Kill(TargetPath + "\" + ifile)
FileCopy(SourcePath + "\" + ifile, TargetPath + "\" + ifile)
Kill(SourcePath + "\" + ifile)
End If
End While
The first call to "Dir" returns the second file in the folder, or no filename if only 1 file is in the folder.