pete1234 Posted July 19, 2008 Share Posted July 19, 2008 I currently have 2 loops that function perfectly on their own. One loop checks the contents of a folder every 30 seconds, and the other loop checks to see what the default printer is every 30 minutes. I want to nest these loops together, so the script checks the folder every 30 seconds, but additionally checks the printer status every half hour. This is the first: expandcollapse popupGlobal $FolderName = "Test" Global $SourcePath = @HomeDrive & "\" & $FolderName & "\" Global $WatchPath = $SourcePath & "*.*" Global $TargetPath = @HomeDrive & "\Processed\" Global $WatchTime = 20 * 1000 ;Check every 20 seconds Global $TimeStamp = TimerInit() While 1 If TimerDiff($TimeStamp) >= $WatchTime Then $FindFile = FileFindFirstFile($WatchPath) If $FindFile <> -1 Then While 1 $FoundFile = FileFindNextFile($FindFile) If @error Then ExitLoop $MovedFile = $TargetPath & @MON & "-" & @MDAY & "-" & @YEAR & "-" & @HOUR & "-" & @MIN & "-" & @SEC & "." & $FoundFile $MoveIt = FileMove($SourcePath & $FoundFile, $MovedFile, 9) If $MoveIt <> 1 Then $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body & $FoundFile & " was not moved.", $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then $ErrorLog = FileWrite($TargetPath & "error.log", "Error:" & @error & " Rc:" & $rc) If $ErrorLog <> 1 Then MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc, 30) EndIf EndIf ExitLoop EndIf Global $PathSplit = _PathSplit($MovedFile, $szDriveFile, $szDirFile, $szFNameFile, $szExtFile) Global $PathExt = $PathSplit[4] If $PathExt = ".pdf" Then $PrintIt = _FilePrint($MovedFile) If $PrintIt <> 1 Then $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body & $FoundFile & " was not printed.", $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then $ErrorLog = FileWrite($TargetPath & "error.log", "Error:" & @error & " Rc:" & $rc) If $ErrorLog <> 1 Then MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc, 30) EndIf EndIf EndIf EndIf If $PathExt = ".tif" Or $PathExt = ".tiff" Then Local $TifInfoPath = @TempDir & $PathSplit[3] & ".txt" Local $Irfantest = RunWait($IrfanViewExe & " " & $MovedFile & " " & "/info=" & $TifInfoPath) Local $TifReadSize = IniRead($TifInfoPath, $PathSplit[3] & $PathSplit[4], "Print size", "Oops!") Local $TifSize = StringReplace(StringStripWS(StringRight($TifReadSize, 18),8),"inches","") FileDelete($TifInfoPath) If $TifSize = $11x17 Then IniWrite($IrfanViewIni, "Print", "SizeTxt", "11x17") EndIf If $TifSize = $Legal Then IniWrite($IrfanViewIni, "Print", "SizeTxt", "Legal") EndIf If $TifSize <> $11x17 And $TifSize <> $Legal Then ;If print size isn't Legal or 11x17, default to Letter IniWrite($IrfanViewIni, "Print", "SizeTxt", "Letter") EndIf RunWait($IrfanViewExe & " " & $MovedFile & " " & "/print") EndIf If $PathExt <> ".pdf" And $PathExt <> ".tif" And $PathExt <> ".tiff" Then $rc = _INetSmtpMailCom($s_SmtpServer, $s_FromName, $s_FromAddress, $s_ToAddress, $s_Subject, $as_Body & $FoundFile & " is not a printable file.", $s_AttachFiles, $s_CcAddress, $s_BccAddress, $s_Username, $s_Password, $IPPort, $ssl) If @error Then $ErrorLog = FileWrite($TargetPath & "error.log", "Error:" & @error & " Rc:" & $rc) If $ErrorLog <> 1 Then MsgBox(0, "Error sending message", "Error code:" & @error & " Rc:" & $rc, 30) EndIf EndIf EndIf WEnd EndIf $TimeStamp = TimerInit() EndIf Sleep(20) WEndoÝ÷ Ø Ý¶¬ËazÇ¢wZºÚ"µÍÌÍÔ[Ø]Ú[YHHN LÈÚXÚÈY][[]H[ÝÌÍÔ[[YTÝ[H[Y[] BÚ[HBY[YY ÌÍÔ[[YTÝ[ H ÝÏH ÌÍÔ[Ø]Ú[YH[ ÌÍÔ[ÚXÚÈHÑÙ]Y][[ BIÌÍÔ[XYH[TXY ÌÍÒ[Y]Ò[K ][ÝÔ[ ][ÝË ][ÝÔ[][ÝË ][ÝÓÛÜÉÌÌÎÉ][ÝÊBY ÌÍÔ[ÚXÚÈ ÉÝÈ ÌÍÔ[XY[BBR[UÜ]J ÌÍÒ[Y]Ò[K ][ÝÔ[ ][ÝË ][ÝÔ[][ÝË ÌÍÔ[ÚXÚÊB[Y ÌÍÔ[[YTÝ[H[Y[] B[YÛY BÑ[ I've tried placing the second loop before the last WEnd/after the first While of the first loop, but one loop always overrides the other. How can I get the two to co-exist? Thanks a bunch. Link to comment Share on other sites More sharing options...
bogQ Posted July 19, 2008 Share Posted July 19, 2008 I currently have 2 loops that function perfectly on their own. One loop checks the contents of a folder every 30 seconds, and the other loop checks to see what the default printer is every 30 minutes. I want to nest these loops together, so the script checks the folder every 30 seconds, but additionally checks the printer status every half hour. so you need "func" (at least its what i use for that situations) Global $looping = "" _loop1() ;<== start first part of your script While 1 WEnd Func _loop1() While 1 $looping = $looping + 1 ;<== count how many times did you loop ;<== your first part of the script If $looping > "60" Then ;<== every 30 seconds * 60 = 30 minutes $looping = "" ;<== reset looping count _loop2() ;<== goto second part of script EndIf Sleep(30000);<== loop every 30 seconds WEnd EndFunc Func _loop2() While 1 ;<== your second part of the script _loop1() ;<== goback to the first part of script WEnd EndFunc TCP server and client - Learning about TCP servers and clients connectionAu3 oIrrlicht - Irrlicht projectAu3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related) There are those that believe that the perfect heist lies in the preparation.Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost. Link to comment Share on other sites More sharing options...
pete1234 Posted July 19, 2008 Author Share Posted July 19, 2008 (edited) blech While 1 If TimerDiff($PrintTimeStamp) >= $PrintWatchTime Then $PrintCheck = _GetDefaultPrinter() $PrintRead = IniRead($IrfanViewIni, "Print", "Printer", "oops!") If $PrintCheck <> $PrintRead Then IniWrite($IrfanViewIni, "Print", "Printer", $PrintCheck) EndIf $PrintTimeStamp = TimerInit() EndIf If TimerDiff($TimeStamp) >= $WatchTime Then and so on My problem was I was viewing it as 2 loops instead of 1. This seems to work so far. Edit: boqQ - I didn't see your reply before posting. I will play around with your idea and see if it works as well. Edited July 19, 2008 by pete1234 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