Jump to content

Mass Renaming


 Share

Recommended Posts

I have a folder with 1163 pictures in it and I want all of them renamed numerically. (Starting at 1 and going to 1163)

I know that there is no FileRename() function, so I have to use FileMove() However, this only does 1 file at a time...so rather than me having to hit F5 1163 times, I was hoping there was some way to make it do all the files...

my code is:

Global $Num = Random(0,1163,1)

While 1
     FileMove("C:\Users\Justin\Desktop\Folder\*.jpg","C:\Users\Justin\Desktop\Folder\" & $Num & ".jpg")
WEnd

It works, but only one 1 file at a time...how do I make it rename all the files at once?

Edited by xPloit

00101101011110000101000001101100011011110110100101110100

Link to comment
Share on other sites

If you were going to globally insert/append the same string onto all the target files, like sticking ".bak" on the end of the filenames, you could do it in one fell swoop. But, since you're specifying a different name for each file, you have to go one-at-a-time. Something like:

#include <File.au3>

Global Const $Path = "C:\Users\Justin\Desktop\Folder\"
Global $Array = _FileListToArray($Path, "*.jpg", 1)

For $x = 1 to $Array[0]
    FileMove($Path & $Array[$x], $Path & $x & ".jpg")
Next

edit: typo

Edited by Spiff59
Link to comment
Share on other sites

I have a folder with 1163 pictures in it and I want all of them renamed numerically. (Starting at 1 and going to 1163)

I know that there is no FileRename() function, so I have to use FileMove() However, this only does 1 file at a time...so rather than me having to hit F5 1163 times, I was hoping there was some way to make it do all the files...

my code is:

Global $Num = Random(0,1163,1)

While 1
     FileMove("C:\Users\Justin\Desktop\Folder\*.jpg","C:\Users\Justin\Desktop\Folder\" & $Num & ".jpg")
WEnd

It works, but only one 1 file at a time...how do I make it rename all the files at once?

Stick it in a loop, and increment the loop counter ($num) from 1 to 1163.

Pseudo code:
For $Num = 1 to 1163
     Rename
Next $Num
Link to comment
Share on other sites

$sFldr = "C:\Some\folder\" 
$hSrch = FileFindFirstFile($sFldr & "*.jpg")
If NOT @Error Then
    $i = 1
    While 1
        $sFile = FileFindNextFile($hSrch)
        If @Error Then ExitLoop
        If FileMove($sFldr & $sFile, $sFldr & $i & ".jpg") Then $i += 1
    WEnd
EndIf
FileClose($hSrch)

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...