markham Posted November 30, 2012 Share Posted November 30, 2012 Hello, postscript files 3 sprecifics lines : %%Pages: (atend) //i want to ignore this one %%Pages: 4 // i want extract the number (here : 4) userdict /#copies 50 put (here : 50) but my following codes seems doesn't work and don't know why. can you help me ? dim $PostscriptFile='20121123172655.ps' dim $copies=1 dim $pages=1 $file = FileOpen($PostscriptFile, 0) If $file = 0 Then MsgBox(0, "Error", "Unable to open file.") Exit EndIf ; Read in lines of text until the EOF is reached While 1 Local $line = FileReadLine($file) If @error = -1 Then ExitLoop if StringInStr($line,"%%Pages:",1,2) >0 then $array1= StringRegExp($line,"%%Pages:\h\(d+)",3) $pages = Number($array1[0]) EndIf if StringInStr($line,"/#copies",1,1)>0 then $array2= StringRegExp($line,"/#copies\h\(d+)",3) $copies = Number($array2[0]) EndIf WEnd FileClose($file) MsgBox(0,"total pages",$copie * $pages) thx a lot Link to comment Share on other sites More sharing options...
JohnOne Posted November 30, 2012 Share Posted November 30, 2012 but my following codes seems doesn't work and don't know why.can you help me ?Be more specific. 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...
markham Posted November 30, 2012 Author Share Posted November 30, 2012 Be more specific.$pages and $copies stay at 1. Link to comment Share on other sites More sharing options...
JohnOne Posted November 30, 2012 Share Posted November 30, 2012 could be that you are redeclaring in a loop Local $line = FileReadLine($file) 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...
markham Posted November 30, 2012 Author Share Posted November 30, 2012 i use this example :http://www.autoitscript.com/autoit3/docs/functions/FileReadLine.htm Link to comment Share on other sites More sharing options...
JohnOne Posted November 30, 2012 Share Posted November 30, 2012 Might be that the regex is wrong, but try it like this.Local$line=FileReadLine($file)While1If@error=-1ThenExitLoopMsgBox(0,"Line read:",$line) $line=FileReadLine($file)WEnd 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...
JohnOne Posted November 30, 2012 Share Posted November 30, 2012 Sorry, I don't see increment, add $line += 1 in loop 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...
jchd Posted November 30, 2012 Share Posted November 30, 2012 In your regexp patterns, are misplaced. Try:Local $PostscriptFile = '20121123172655.ps' Local $aRes, $copies = 1, $pages = 1 $file = FileRead($PostscriptFile) If Not @error Then $aRes = StringRegExp($file, "(?i)%%Pages:h*(d+)", 1) If Not @error Then $pages = Number($aRes[0]) ;~ Else ;~ ConsoleWrite("%%Pages not found" & @LF) EndIf $aRes = StringRegExp($file, "(?i)/#copiesh*(d+)", 1) If Not @error Then $copies = Number($aRes[0]) ;~ Else ;~ ConsoleWrite("/#copies not found" & @LF) EndIf MsgBox(0,"Total pages", $copies * $pages) Else ConsoleWrite("Unable to read file " & $PostscriptFile & @LF) EndIf This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
markham Posted November 30, 2012 Author Share Posted November 30, 2012 it's work perfectly !!! thx a lot !!! 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