Link to home
Start Free TrialLog in
Avatar of Jody Reid
Jody ReidFlag for United States of America

asked on

Moving file and renaming them.

I have about 10,000 file that I need to move and rename. Is there a way with a batch file that i could move x amount of these files and rename them at the same time. This is what i need to do. I have about 60-70 with the name AA091.tif , AA092.tif and so on. I need to put a letter at the end of all thes file " AA091A, AA092A and so on" Then i have 60-70 in another folder that i need to move and rename but the have th esame name e.g. " AA091.tif and i need to rename these AA091B.tif and so on.
I have about 10 folder with about 10,000 file. I do not want to go and rename each file one by one.
Thank you.
Avatar of MacNuttin
MacNuttin
Flag of United States of America image

To put in a batch file, and I've tested this, it moves and renames with "old" prefix

@echo off
for %%i in (*.tif) do move %%i new/path/old%%i
Avatar of v_karthik
v_karthik

I wrote a perl script for this long back .. mainly to rename my digital photos in one shot ... You can download and use it if you have perl (u can get it for free from www.activeperl.com)

http://www.employees.org/~vkarthik/downloads.html#bulkrename

If you are using it let me know if you have trouble.
Avatar of Jody Reid

ASKER

These are not helping much. This is how i am renaming the files but it does not work very well.
@echo off
Ren R:\test\A*.* A*A.*  

the end result is that instead of getting
from this AA019.tif   to AA019A.tif
i am getting

AA019.tifA

Why is this happening.
Thank you.

This will rename all the file name to old. I just want to add A to the end of the file name. (AA019.tif change to AA019A.tif). I have 10 different folders a,b,c,d and so on with the same file name in each e.g in the A folder i have AA019.tif and in the B folder i have AA019.tif and so on. I need to just add the letter of the folder to the end of the file name.
Is this possible with batch code.
Thank you.
Well if you have VB2005,


something similar to this could be tweaked to rename the files. You could make a console app to do it if you like or just
hard code and run.


        'change c:\ to appropriate directory; tif is set to be the only type of files renamed..change as desired
        'this is quickly done and not tested, but you should get the idea
        Dim Files() As String = System.IO.Directory.GetFiles("c:\", "*.tif")
        Dim fi As FileInfo
        For Each S As String In Files
            fi = New System.IO.FileInfo(S)
            System.IO.File.Move(fi.FullName, fi.Name & "A" & fi.Extension)
        Next
The point is with my code in a bat file and change the "old" to "A" ,the new/path to your directory and it will do what you what except it puts the "A" at the beginning of the filename. Sorry - play with it a little and maybe you can get the A or B or whatever where you want it
Thank you but this is what i have done. I am going to take it in two stages.
1. I am going to Rename all the file.
This is the batch file I have
@echo off
cls
Ren R:\ECHART\A\F*.tif F??????A.tif
@echo on

This puts the A at the end of the file name but i have to change the the batch every time for all the leters i.e.
'Ren R:\ECHART\A\F*.tif F??????A.tif
to
Ren R:\ECHART\A\G*.tif G??????A.tif and so on. Is the a way to have it this change the letter for me with out changing the Batch file.
2. I am going to copy the files over after i change the Name.
Thank you
ASKER CERTIFIED SOLUTION
Avatar of MacNuttin
MacNuttin
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Imports system.io

File.Move("d:\source", "c:\destination")