Jump to content

Best Practice for renaming a bunch of files


Go to solution Solved by JLogan3o13,

Recommended Posts

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

  • Moderators

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?

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators
  • Solution

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

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

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

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