nondrinker
Programmer
Hello,
I am trying to add the string "XYZ" to each file name and then move my files from folderA to folderB.
This is the code that i have so far.
**********************************
Private Const varSourceAddress As String = "\\serverA\drivename\FolderA\"
Dim diaddr As New DirectoryInfo(varSourceAddress)
Dim fiaddr As FileInfo() = diaddr.GetFiles()
While diaddr.GetFiles.Length > 0
For Each scannedFile As FileInfo In fiaddr
If scannedFile.Name.Contains("Thumbs") = False Then
If scannedFile.Exists Then
strOldName = scannedFile3.Name
strNewName = strOldName.Insert(14, "XYZ")
scannedFile.CopyTo("\\serverA\drivename\FolderB\" & strNewName, True)
scannedFile.Delete()
strOldName = ""
strNewName = ""
End If
End If
Next
End While
************************************************
I am using this code in a windows service. When this code executes for the first time, everything happens the way it's suppose to be. It does add XYZ to every file's name and the files get moved to folderB also. However, upon the second run, it sends an error message:
System.IO.FileNotFoundException: Could not find file '\\serverA\drivename\folderA\20130327082003.pdf'.
I can see that the file 20130327082003.pdf has already been moved to folderB with the new name of 20130327082003XYZ.pdf and that is all fine, but the service keeps checking for the same file name in folderA. I have tried rename, move commands also, but instead of checking for the new files (if any) in folderA the system keeps checking for the file that has already been moved to folderB. I am using .Delete method to delete the file (or any reference) once it has been copied to folderB, but that doesn't seem to make any difference.
Once the service will be running, eventually it's suppose to move every new file generated in folderA (after adding XYZ to its name) to folderB.
Any help will be appreciated.
Thank you.
I am trying to add the string "XYZ" to each file name and then move my files from folderA to folderB.
This is the code that i have so far.
**********************************
Private Const varSourceAddress As String = "\\serverA\drivename\FolderA\"
Dim diaddr As New DirectoryInfo(varSourceAddress)
Dim fiaddr As FileInfo() = diaddr.GetFiles()
While diaddr.GetFiles.Length > 0
For Each scannedFile As FileInfo In fiaddr
If scannedFile.Name.Contains("Thumbs") = False Then
If scannedFile.Exists Then
strOldName = scannedFile3.Name
strNewName = strOldName.Insert(14, "XYZ")
scannedFile.CopyTo("\\serverA\drivename\FolderB\" & strNewName, True)
scannedFile.Delete()
strOldName = ""
strNewName = ""
End If
End If
Next
End While
************************************************
I am using this code in a windows service. When this code executes for the first time, everything happens the way it's suppose to be. It does add XYZ to every file's name and the files get moved to folderB also. However, upon the second run, it sends an error message:
System.IO.FileNotFoundException: Could not find file '\\serverA\drivename\folderA\20130327082003.pdf'.
I can see that the file 20130327082003.pdf has already been moved to folderB with the new name of 20130327082003XYZ.pdf and that is all fine, but the service keeps checking for the same file name in folderA. I have tried rename, move commands also, but instead of checking for the new files (if any) in folderA the system keeps checking for the file that has already been moved to folderB. I am using .Delete method to delete the file (or any reference) once it has been copied to folderB, but that doesn't seem to make any difference.
Once the service will be running, eventually it's suppose to move every new file generated in folderA (after adding XYZ to its name) to folderB.
Any help will be appreciated.
Thank you.