Archivist Posted July 20, 2010 Share Posted July 20, 2010 I have a For Next loop I'm having a bit of trouble getting to work. Here's a simplified version of my script to give an idea of what I'm doing. This version of the script iterates over a series of filenames with a regular naming format. It assembles a filename variable out of the current loop variable number, then checks to see if a PDF exists in the \pic\ subdirectory. If it does, it calls PDFTK (which exists in the directory where the script is being called) and performs an operation; if not, it copies a file from one directory to another. When I run the script, it immediately closes without running through the loop, and never calls PDFTK or copies the file. I'm having trouble figuring out what I did wrong, though I'm sure it must be simple. $format = "2010CO001" For $a = 1 to 273 Step 1 If StringLen ($a) = 1 then $filename = $format + ".000" & $a If StringLen ($a) = 2 then $filename = $format + ".00" & $a If StringLen ($a) = 3 then $filename = $format + ".0" & $a If FileExists(@ScriptDir & "\pic\" & $filename & ".pdf") Then RunWait("pdftk " & @ScriptDir & "\dj\" & $filename & ".pdf " & "stamp " & @ScriptDir & "\pic\" & $filename & ".pdf " & @ScriptDir & "\out\" & $filename & ".pdf") Else FileCopy(@ScriptDir & "\dj\" & $filename & ".pdf",@ScriptDir & "\out\" & $filename & ".pdf") EndIf Next Link to comment Share on other sites More sharing options...
JohnOne Posted July 20, 2010 Share Posted July 20, 2010 You need to do some debugging to find out whats happening look up @error in helpfile I would start though by putting Beep (800,200) after your run function and Beep (800,200) Beep (800,200) after your filemove function see whats supposed to have happened. AutoIt Absolute Beginners Require a serial Pause Script Video Tutorials by Morthawt ipify Monkey's are, like, natures humans. Link to comment Share on other sites More sharing options...
AndyG Posted July 20, 2010 Share Posted July 20, 2010 it would be better if you had posted some of the filenames you want to run $format = "2010CO001" For $a = 1 to 273 Step 1 If StringLen ($a) = 1 then $filename = $format + ".000" & $a If StringLen ($a) = 2 then $filename = $format + ".00" & $a If StringLen ($a) = 3 then $filename = $format + ".0" & $a ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $filename = ' & $filename & @crlf & '>Error code: ' & @error & @crlf) ;### Debug Console If FileExists(@ScriptDir & "\pic\" & $filename & ".pdf") Then RunWait("pdftk " & @ScriptDir & "\dj\" & $filename & ".pdf " & "stamp " & @ScriptDir & "\pic\" & $filename & ".pdf " & @ScriptDir & "\out\" & $filename & ".pdf") Else FileCopy(@ScriptDir & "\dj\" & $filename & ".pdf",@ScriptDir & "\out\" & $filename & ".pdf") EndIf Nextthe script shows the filenames you create, it seems they are wrong....or are they right? Link to comment Share on other sites More sharing options...
Archivist Posted July 20, 2010 Author Share Posted July 20, 2010 You're right, the filenames seem to be wrong. I typoed + in place of &, which resulted in pretty wrong filenames. After I corrected that, and my PDFTK syntax, it seems to be working. Thanks a lot! I'll try to apply what I learned here to the longer, more complex version of the script. 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