Jump to content

[Solved] Rename all files in a folder


Recommended Posts

Hey,

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")
Exit
EndIf

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

FileClose($search)
Edited by IanN1990
Link to comment
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])
Next
_ArraySort($array)
_ArrayDisplay($array)

; 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.
Link to comment
Share on other sites

$test= _
'1' & @CRLF & _
'11' & @CRLF & _
'111' & @CRLF & _
'12' & @CRLF & _
'2' & @CRLF & _
'21' & @CRLF & _
'22' & @CRLF & _
'3'
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.

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...