AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Rename all files in a directory based on current names

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
stuboo



Joined: 17 Apr 2007
Posts: 22

PostPosted: Mon Aug 03, 2009 2:28 am    Post subject: Rename all files in a directory based on current names Reply with quote

I've got a directory full of images that I need to rename. The current naming scheme is...

Slide1.gif
Slide2.gif
Slide3.gif
Slide4.gif
...
Slide30.gif

and I'd like to use AHK to rename them to...

001.gif
002.gif
003.gif
004.gif
...
030.gif

It is important that the slide numbers in the current set match the file numbers in the renamed files - these are slides exported from PowerPoint, so it is critical that they stay in the appropriate order.

Thanks,
Ryan
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Mon Aug 03, 2009 3:03 am    Post subject: Reply with quote

Should work fine for up to Slide99.gif
Code:
Directory = %A_Desktop% ; or whatever directory

Loop, %Directory%\*.gif
{   StringReplace, name, A_LoopFileName, Slide
   StringReplace, name, name, .gif
   FileCopy, % Directory "\" A_LoopFileName, % Directory (name<10 ? "\00" : "\0") name ".gif"
   FileDelete, % Directory "\" A_LoopFileName
}
Return

_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
stuboo



Joined: 17 Apr 2007
Posts: 22

PostPosted: Mon Aug 03, 2009 3:20 am    Post subject: Reply with quote

Brilliant! Thanks so much. I thought I was going to have to do this in PHP after I uploaded the file, but this is the better way. I really appreciate it.
_________________
---
I used AutoHotKey to write this signature crazy fast.
Back to top
View user's profile Send private message
stuboo



Joined: 17 Apr 2007
Posts: 22

PostPosted: Mon Aug 03, 2009 1:39 pm    Post subject: Reply with quote

Quote:
Should work fine for up to Slide99.gif


How can I make it work up to Slide999.gif?
_________________
---
I used AutoHotKey to write this signature crazy fast.
Back to top
View user's profile Send private message
jethrow



Joined: 24 May 2009
Posts: 1907
Location: Iowa, USA

PostPosted: Mon Aug 03, 2009 1:46 pm    Post subject: Reply with quote

Code:
Directory = %A_Desktop% ; or whatever directory

Loop, %Directory%\*.gif
{   StringReplace, name, A_LoopFileName, Slide
   StringReplace, name, name, .gif
   FileCopy, % Directory "\" A_LoopFileName, % Directory (name<10 ? "\00" : (name<100 ? "\0" : "\")) name ".gif"
   FileDelete, % Directory "\" A_LoopFileName
}
Return

_________________
Very Happy - in case I forgot to smile
Basic Webpage Controls
COM Object Reference
Back to top
View user's profile Send private message Visit poster's website Yahoo Messenger
Gaurang
Guest





PostPosted: Thu Aug 06, 2009 7:07 am    Post subject: Reply with quote

I have a similar query please – I would like to rename a few files (these should not exceed more than 250 in total) that look like this –

Case Fragment_01_01Aug09_090304.xls
Case Fragment_02_01Aug09_112319.xls
Case Fragment_03_01Aug09_144221.xls
Case Fragment_04_01Aug09_185632.xls

Use AHK to rename them to -

Case Fragment_01_01Aug09.xls
Case Fragment_02_01Aug09.xls
Case Fragment_03_01Aug09.xls
Case Fragment_04_01Aug09.xls

In the above file names - Case Fragment_01_, Case Fragment_02_, Case Fragment_03_ etc. remains constant everyday. The file name is then followed by the current date and the current time when the file was generated, like for file number one it was at 09:03:04am and for file number four it was at 06:56:32pm and the date for all files being 01/Aug/2009.

Can I please have two codes to rename the files – one that will simply rename the files by stripping all the information after the date (basically the time value inserted in the file – as shown above) and another code that will also strip all the information after the date as done above but will rename the file depending on the current system date - that is – if I were to run it today to rename then the file names would –

Look like this -

Case Fragment_01_06Aug09.xls
Case Fragment_02_06Aug09.xls
Case Fragment_03_06Aug09.xls
Case Fragment_04_06Aug09.xls

From this -

Case Fragment_01_01Aug09_090304.xls
Case Fragment_02_01Aug09_112319.xls
Case Fragment_03_01Aug09_144221.xls
Case Fragment_04_01Aug09_185632.xls
Back to top
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group