PC Review


Reply
Thread Tools Rate Thread

Batch file rename macro

 
 
simon@bucknall.org
Guest
Posts: n/a
 
      8th Mar 2008
Just thought i'd give a couple of things back to this group as it has
helped me so much.

When I was setting up my website i had to rename thousands of images
with their product codes and was a nightmare. I had the old names and
new names in a spread sheet and so wrote this macro to rename the
files.



Sub FileRenamer()
'
' FileRenamer Macro
'
For Each cell In Columns("A").SpecialCells(xlCellTypeConstants)
If Dir(cell.Value) <> "" And cell.Offset(0, 1).Value <> ""
Then
Name cell.Value As cell.Offset(0, 1).Value
End If
Next cell
'
End Sub


on sheet one of my spread sheet in column A i had the old file name
including the whole file path.

C:\Documents and Settings\SimonBucknall\Desktop\Images\002 9801.jpg

and in column B i had the new name including file path

C:\Documents and Settings\SimonBucknall\Desktop\images webcoded\2.jpg

the macro then reads column A and if it finds the file replaces it's
name/path with the coresponding value in column B.

Make sure both the folders exist, I copied the file path name from one
of the origonal image property boxes and pasted it in to another
spread sheet, in the next column pasted the file name and in the third
the file suffix.

Column A
C:\Documents and Settings\SimonBucknall\Desktop\Images\

Column B
002 9801

Column C
..jpg

saved the file as a csv file, opened it in word and using the replace
function removed the ",". then saved it again and opened the file in
excel. this was the only way i could merge the cells. I suspect there
is a much easier way to do this but i couldn't find it - if there is
please let me know. I then pasted this new column in to my replace
spreadsheet. Repeat the process for the destination file name, run the
macro and you should see all your files renamed in the second folder
(or same if you used the same file path). Those not renamed will
remain unchanged.

I hope this is of use to someone, it has been invalueable to me. Sorry
if the code is not very "correct" or neat but I had to teach myself.
If you can improve on it the pleas let me know.

Simon B
www.ultimatebikes.com

running on office 2007



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Rename in a batch file =?Utf-8?B?c2ltb25j?= Windows XP General 1 18th Dec 2006 12:22 PM
batch file rename shank Microsoft Windows 2000 CMD Promt 4 14th Nov 2006 05:03 PM
Batch file rename? Justin Windows XP General 8 21st Dec 2005 03:09 PM
Batch File Rename richk Freeware 3 4th Dec 2005 11:27 AM
Rename from batch file? Tom McDonald Freeware 19 5th Apr 2004 01:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:18 PM.