Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Rename existing image files and move to new folder 1

Status
Not open for further replies.

Corinne30

Programmer
Mar 24, 2011
16
US
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!!






 

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

Code:
System.IO.File.Move("C:\temp\test1\[red]test.txt"[/red], "C:\temp\test2\[red]test_moved.txt[/red]")

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

Code:
System.IO.File.[red]Copy[/red]("C:\temp\test1\[red]test.txt"[/red], "C:\temp\test2\[red]test_moved.txt[/red]")

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!
 
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

 
If this is your text file:

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

I can see [blue][tt]20120404.AEY[/tt][/blue] in your text file, but could you point me to [red][tt]37_0001.tif[/tt][/red] 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.
 
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

 

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!
 
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.
[tt]
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
[/tt]

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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top