Sign in to follow this  
Followers 0
xPloit

Mass Renaming

5 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



See the example under FileFindNextFile from Help.


SNMP_UDF ... for SNMPv1 and v2c so far, GetBulk and a new example script

wannabe "Unbeatable" Tic-Tac-Toe

Paper-Scissor-Rock ... try to beat it anyway :)

Share this post


Link to post
Share on other sites

#3 ·  Posted (edited)

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

Share this post


Link to post
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

Share this post


Link to post
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!"

Share this post


Link to post
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
Sign in to follow this  
Followers 0