Jump to content
Sign in to follow this  

[Solved] Rename all files in a folder

Recommended Posts



I have a big folder for tri-screen wallpers but its has sooo many pictures and over time i deleted alot. Which has lead to bad numbering. Ie 300, 311, 312, 313 etc.

I wanted to use autoit to rename it all for me but i seam to hit a problem when it does the numbering like 1, 11, 12, 13, 14, 15, 16, 17, 18, 19, 2, 21, etc

How can i fix this ?

$search = FileFindFirstFile("*.jpg*")
local $i = 0
local $file

If $search = -1 Then
MsgBox(0, "Error", "No files/directories matched the search pattern")

While 1
$file = FileFindNextFile($search)
If @error Then ExitLoop
FileMove($file, $i & ".jpg")
$i = $i + 1

Edited by IanN1990

Share this post

Link to post
Share on other sites

from what i'm reading, it apperas that FileFindFirstFile, and nextfile, sort by alpha, not integer...so if you get the file list, and sort it as an integer, then loop through that, to rename the files, you should be fine...let me know if that's not the case...here is how to sort by integer:

#include <Array.au3>
#include <File.au3>
$array = _FileListToArray ( "path", "*.jpg", 1 ) ; use this to populate the array
dim $array[5]=[0,"1.jpg", "5.jpg", "3.jpg","8.jpg"] ; this is just for debugging
For $i = 1 to UBound ( $array ) - 1
$array[$i] = Int($array[$i])

; Then loop through the above array, and append a .jpg to the end, to find the file and rename it.

edit: simplified to only use Int...no need to remove .jpg

Edited by jdelaney

IEbyXPATH-Grab IE DOM objects by XPATH IEscriptRecord-Makings of an IE script recorder ExcelFromXML-Create Excel docs without excel installed GetAllWindowControls-Output all control data on a given window.

Share this post

Link to post
Share on other sites

Works a treat thanks :)

Ur code might also be able to help me fix a problem in my context menu as well, kinda funny how one soluation could fix another.

Edited by IanN1990

Share this post

Link to post
Share on other sites

$test= _
'1' & @CRLF & _
'11' & @CRLF & _
'111' & @CRLF & _
'12' & @CRLF & _
'2' & @CRLF & _
'21' & @CRLF & _
'22' & @CRLF & _
MsgBox(0, "-", $test)

$test=StringRegExpReplace($test, '(d+)', '0000000000001')
$test=StringRegExpReplace($test, '.*(d{4})', '00001')
MsgBox(0, "Yes", $test)

On the "RegEx" tab to execute replacement

1. '(d+)' -> '0000000000001'

2. '.*(d{4})' -> '00001'

On the "Generation" tab to create new numbers.

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  


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.