Jump to content

Renaming files with AutoIt


Recommended Posts

What I would like to do is read the files in a directory. Copy all of the files to a sub directory of the original directory called "Padded". The script would then pad the names of the copied files to a user defined length with a user defined character.

Example

c:\Test\Fred.bat

c:\Test\George.bat

padding to 12 characters with an x would give

c:\Test\xxxxxxxxFred.bat

c:\Test\xxxxxxGeorge.bat

Thanks

Link to comment
Share on other sites

This should start you out, you might want to put in something to make sure your filename length > Pad length. and you can set up your directory you want by changeing my text, or by setting up one more input box or directory find.

Dim $pad,$padnum,$padlet
$pad = InputBox("Question", "What letter for pad?", "X" )
$padnum = int(InputBox("Question", "How much padding?", "12" ))

for $i=1 to $padnum
$padlet=$padlet&$pad
next

; Shows the filenames of all files in the current directory
$search = FileFindFirstFile("*.*")  

; Check if the search was successful
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
    if FileGetAttrib ( $file )<>"d" then
    $pad=Stringright($padlet & $file,$padnum + 4)
    FileCopy ( $file, "padded\" & $pad)
    endif
WEnd

; Close the search handle
FileClose($search)

AutoIt3, the MACGYVER Pocket Knife for computers.

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