reaper1gulf Posted April 17, 2014 Share Posted April 17, 2014 (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 April 17, 2014 by reaper1gulf Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted April 17, 2014 Moderators Share Posted April 17, 2014 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 More sharing options...
reaper1gulf Posted April 17, 2014 Author Share Posted April 17, 2014 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 Link to comment Share on other sites More sharing options...
Moderators Solution JLogan3o13 Posted April 17, 2014 Moderators Solution Share Posted April 17, 2014 So I would do something like this: Beginning with this path as an example: 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 More sharing options...
reaper1gulf Posted April 17, 2014 Author Share Posted April 17, 2014 Thanks Logan, I'll give this a try and let you know how it works Link to comment Share on other sites More sharing options...
JohnQSmith Posted April 17, 2014 Share Posted April 17, 2014 (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 April 17, 2014 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 More sharing options...
Moderators JLogan3o13 Posted April 17, 2014 Moderators Share Posted April 17, 2014 We're giving them AutoIt fish, not command line guppies reaper1gulf 1 "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 More sharing options...
reaper1gulf Posted April 17, 2014 Author Share Posted April 17, 2014 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 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now