473,499 Members | 1,747 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Renaming and moving files.

1 New Member
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.

**********************************
Expand|Select|Wrap|Line Numbers
  1. Private Const varSourceAddress As String = "\\serverA\drivename\FolderA\"
  2. Dim diaddr As New DirectoryInfo(varSourceAddress)
  3. Dim fiaddr As FileInfo() = diaddr.GetFiles()
  4.  
  5. While diaddr.GetFiles.Length > 0
  6. For Each scannedFile As FileInfo In fiaddr
  7. If scannedFile.Name.Contains("Thumbs") = False Then
  8. If scannedFile.Exists Then
  9. strOldName = scannedFile.Name
  10. strNewName = strOldName.Insert(14, "XYZ")
  11. scannedFile.CopyTo("\\serverA\drivename\FolderB\" & strNewName, True)
  12. scannedFile.Delete()
  13.  
  14. strOldName = ""
  15. strNewName = ""
  16.  
  17. End If
  18. End If
  19. Next
  20. End While 
  21.  
************************************************
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.
Mar 28 '13 #1
1 1215
Rabbit
12,516 Recognized Expert Moderator MVP
It's probably because you never refresh your fiaddr variable.
Mar 29 '13 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2381
by: Hubert Wong | last post by:
Hi, I am writing some C# code that moves files from a source folder to a target folder on the same machine. However, if the target folder is a shared folder, using the File.MoveTo method alone...
5
6447
by: Robizzle | last post by:
I'm trying to write a simple console app that will rename all the files in a directory according to any rules supplied by a user during runtime. For example rename all *.jpg to *.jpeg. My problem...
1
1160
by: Jaymac | last post by:
Hi folks I have some 1600 files where the first 7 characters of each file name is in the format "CN NNN ". I would like to be able to change these via a program to the format "CN-NNN-". The...
1
1484
by: Jack Maxwell | last post by:
Hope someone can help here. My brother has asked me if I can assist in renaming about 1500 midi files which are associated with a programm called Cubase SE. With that software installed he can...
2
3829
by: Jorgen Bodde | last post by:
Hi all, I want to make a small batch copy tool that scans for certain files, and copies them to a specified directory. Since the files are huge (AVI / DIVX) typical 300 to 700 Mb, I want to...
11
2228
by: Jim in Arizona | last post by:
I've looked around the web but can't find anything to help me out. I was able to get some code to move some files from one directory to another, which works fine: ...
1
860
by: =?Utf-8?B?RXJpYw==?= | last post by:
I have a small hard drive (C) and it’s almost full. Can I cut & paste files from C to another internal drive (E)? I know if I move software I may have to reinstall it but what about files like...
1
1882
by: samercontrol | last post by:
i have two problems 1-moving files between servers or downloading file to your site root(ASP). 2-registering dll or ocx at server without getting the no permission problem.
2
3513
by: rotaryfreak | last post by:
Hi, I was just wondering if it is possible to write a java program that will rename a whole bunch of .mp3 files? if it is possible, how would i go about doing that? thanks!
2
1534
by: fuchsia555 | last post by:
is there any way to move files from old host to new host without upload the files from my computer i have asked my hosting about FXP but they doesn't support it can it be done by any way or by...
0
7012
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7180
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7392
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5479
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4920
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4605
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3105
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
667
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
307
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.