Sign in to follow this  
Followers 0
reaper1gulf

Best Practice for renaming a bunch of files

8 posts in this topic

#1 ·  Posted (edited)

Hey guys, so I'm still fairly new to Autoit and coding in general. What I'm trying to do is rename a bunch of files that are 20 characters long, first 7 characters are always the same, the next 8 are variable and the next 5 are constant, so it would look something like this: A000000ukaelsqc00000.pdf (could be a jpg, tif, bmp as well). There is normally more than 30 files in the folder daily. What I'm attempting to do is rename the file the exact same name, but with a _pdf.pdf (same for other file types). Should I use an array to do this? Or is there another way to accomplish this for a beginner? Thanks in advance :)

Edited by reaper1gulf

Share this post


Link to post
Share on other sites



Just to clarify, you want to change A000000ukaelsqc00000.pdf to A000000ukaelsqc00000_pdf.pdf, A000000ukaelsqc00000.tif to A000000ukaelsqc00000_tif.tif, etc. You're not actually changing anything with the first 20 characters, correct?


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

that's correct, generally they are PDF's, sometimes there can be other file types. I want to keep the same first 20 characters and add a _pdf to the file. So A000000ukaelsqc00000.pdf would turn into A000000ukaelsqc00000_pdf.pdf

Share this post


Link to post
Share on other sites

So I would do something like this:

Beginning with this path as an example:

post-54985-0-17922200-1397748396_thumb.p

I would use one array to contain the files, and another to split the file names, like so:

#include <File.au3>

Local $aArray, $aSplit, $sPath

$sPath = @DesktopDir & "\Test"
$aArray = _FileListToArray($sPath, "*",  1, False)

   For $i = 1 To $aArray[0]
      $aSplit = StringSplit($aArray[$i], ".")
      FileMove($sPath & "\" & $aArray[$i], $sPath & "\" & $aSplit[1] & "_" & $aSplit[2] & "." & $aSplit[2])
   Next

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Thanks Logan, I'll give this a try and let you know how it works :)

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

So I would do something like this:

 

Since we're going to "give a man a fish" today, here's a CMD prompt line you can run in your folder that will do the same thing.

for /f "usebackq tokens=1,2 delims=." %i in (`dir /a-d /b *.*`) do ren %i.%j %i_%j.%j
Edited by JohnQSmith

Whenever someone says "pls" because it's shorter than "please", I say "no" because it's shorter than "yes".

Share this post


Link to post
Share on other sites

We're giving them AutoIt fish, not command line guppies :)

1 person likes this

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

Thank you Logan, all I had to do was change the directory and it works like a charm! And after looking at what you wrote I realize where my code was messed up. Thank you

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