INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Rename existing image files and move to new folder

Rename existing image files and move to new folder

(OP)
Hi,

I'm working in vb.net

What I need to do is to rename image files that exist in a file structure to a new naming convention based on data in a text file. Can anyone look at this and let me know what I need to do???
My text file looks like this:

SCANNED_DATETIME|PERMIT_ID|OLD_NAME
20120404|37|20120404.AEY
20010108|36|20010108.AA7
20130326|34|20130326.AC2


the corresponding image files (C:\Temp\201204\20120404.AEY )are in folders named for example 201204 for the first item in the list. I need to move this image from where it currently is to a new folder named 20120404 and rename the image file to 37_0001.tif

I can easily create a target folder and move them but I don't understand how to rename them.

Please let me know if I can provide any other info.

Thanks!!




RE: Rename existing image files and move to new folder


It's actually really easy, you can rename the file as you move it:

CODE

System.IO.File.Move("C:\temp\test1\test.txt", "C:\temp\test2\test_moved.txt") 

If you want to verify that the copy was successful first then delete the original file:

CODE

System.IO.File.Copy("C:\temp\test1\test.txt", "C:\temp\test2\test_moved.txt")

If System.IO.File.Exists("C:\temp\test2\test_moved.txt") Then
    System.IO.File.Delete("C:\temp\test1\test.txt")
End If 

You can also change the file's extension when moving or copying.



I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: Rename existing image files and move to new folder

(OP)
Hi - Thanks for responding. I'm still missing the point of the renaming if the file. I need to rename it with the ID of the users ID. the file originally named 20120404.AEY needs to be named 37_0001.tif based on the link from my text file. I'm sorry but I'm missing how the example you posted would work.

Thanks

RE: Rename existing image files and move to new folder

If this is your text file:

SCANNED_DATETIME | PERMIT_ID |   OLD_NAME
20120404         |    37     | 20120404.AEY
20010108         |    36     | 20010108.AA7
20130326         |    34     | 20130326.AC2
 
And you say: "the file originally named 20120404.AEY needs to be named 37_0001.tif based on the link from my text file"

I can see 20120404.AEY in your text file, but could you point me to 37_0001.tif in the text file? Unless your logic is: take PERMIT_ID and add to it '_0001' and '_0002' and '_0003' ... But that's just my guess.

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

RE: Rename existing image files and move to new folder

(OP)
Hi Andy,

Thanks for responding.

The logic is to take the permit_id which is unique and append the _0001.tif to it and then rename the file 20120404.AEY to 37_0001.tif and then the next one would be: 20010108.AA7 renamed to 36_0001.tif. I'm just not sure how to be able to do this. Somewhere I saw something about reading the whole file in and doing a file copy source to target but I don't see how I can get the renaming done. Thanks for trying to help me.

Corinne

RE: Rename existing image files and move to new folder


In your original post you said:

"I need to move this image from where it currently is to a new folder named 20120404 and rename the image file to 37_0001.tif"

The code I posted shows how to move and rename the file at the same time. In your case, it would be:

System.IO.File.Move("C:\Temp\201204\20120404.AEY", "C:\new\path\here\37_0001.tif")

This moves the file like you want, and renames it, like you want.

What exactly are you not understanding?

I used to rock and roll every night and party every day. Then it was every other day. Now I'm lucky if I can find 30 minutes a week in which to get funky. - Homer Simpson

Arrrr, mateys! Ye needs ta be preparin' yerselves fer Talk Like a Pirate Day!

RE: Rename existing image files and move to new folder

Corinne needs to incorporate your logic into a little more code.
Read from the text file (provided) and move/rename files from the text file.

Read line of text file
Take OLD_NAME file and move/rename it to PERMIT_ID & "_0001.tif"
Loop to the end of text file

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close