Gibbo Posted January 23, 2015 Posted January 23, 2015 Hi All, I went searching for something to speed up checking for files on the network (UNC Paths) Most examples were rather complicated but someones multi-threaded solution gave me an idea. Hope it is useful to someone. Seems to work well so far. Func _FileExistsTimeout($sPath, $iTimeout = 1000) Local $hTimer = TimerInit() ; Begin the timer and store the handle in a variable. Local $iPID = Run(@AutoItExe & ' /AutoIt3ExecuteLine "ConsoleWriteError(FileExists(""' & $sPath & '""))"', @ScriptDir, @SW_HIDE, $STDERR_CHILD) Local $sOutput = "" Local $iDiff = 0 While $iDiff < $iTimeout $iDiff = TimerDiff($hTimer) $sOutput &= StderrRead($iPID) If @error Then ; Exit the loop if the process closes or StderrRead returns an error. ExitLoop EndIf WEnd ProcessClose($iPID) Switch StringStripWS($sOutput, 8) Case 1 Return True Case Else Return False EndSwitch EndFunc ;==>_FileExistsTimeout
BobMerit Posted May 13, 2024 Posted May 13, 2024 This seems to be a well thought out great function. Solved my issue for sure. Just don't spend hours like me trying figure out why it doesn't work. The author didn't leave a clue about needing the following, you know, because we are already supposed to know this. Right... See https://www.autoitscript.com/autoit3/docs/functions/StderrRead.htm pragma compile(AutoItExecuteAllowed, True) #include <AutoItConstants.au3>
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