| View previous topic :: View next topic |
| Author |
Message |
stuboo
Joined: 17 Apr 2007 Posts: 22
|
Posted: Mon Aug 03, 2009 2:28 am Post subject: Rename all files in a directory based on current names |
|
|
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 |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Mon Aug 03, 2009 3:03 am Post subject: |
|
|
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 |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
stuboo
Joined: 17 Apr 2007 Posts: 22
|
Posted: Mon Aug 03, 2009 3:20 am Post subject: |
|
|
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 |
|
 |
stuboo
Joined: 17 Apr 2007 Posts: 22
|
Posted: Mon Aug 03, 2009 1:39 pm Post subject: |
|
|
| 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 |
|
 |
jethrow
Joined: 24 May 2009 Posts: 1907 Location: Iowa, USA
|
Posted: Mon Aug 03, 2009 1:46 pm Post subject: |
|
|
| 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 |
_________________
- in case I forgot to smile
Basic Webpage Controls
COM Object Reference |
|
| Back to top |
|
 |
Gaurang Guest
|
Posted: Thu Aug 06, 2009 7:07 am Post subject: |
|
|
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 |
|
 |
|