Jdr Posted August 19, 2016 Posted August 19, 2016 (edited) I'm trying to check for the existance of a file, on logon the file is there, then gets deleted and after a while recreated. I'm using this code: Sleep(100) If not FileExists($sFile) Then Sleep(150) If FileExists($sFile) Then GUICtrlSendToDummy($iDummy) What happens is this: User logs on, the file is present, or at least it usually is After about 10 seconds the file gets deleted Then after about 50 seconds the file gets created again, this is when I need the check, because now the process is finished. The above code is part of a pretty long do....until false loop running an animation. The problem is that sometimes this code fails. Without the sleep statements it didn't work at all so I think this is a timing issue. Pretty primitive code I admit, there must be a better way... Edited August 19, 2016 by Jdr typo
Developers Jos Posted August 19, 2016 Developers Posted August 19, 2016 So you currently wait 100Ms (0.10 second) initially, then test for the file and then 150Msecs later you test it again? Jos SciTE4AutoIt3 Full installer Download page - Beta files Read before posting How to post scriptsource Forum etiquette Forum Rules Live for the present, Dream of the future, Learn from the past.
orbs Posted August 19, 2016 Posted August 19, 2016 (edited) if i get this right, then you need to play some animation while your script is waiting for the file to re-appear? well, you can delegate the animation to an external process, and make your waiting loop a lot simpler: ; create the animation While Not FileExists($sFile) Sleep(100) ; check for user clicking a cencellation button WEnd Edited August 19, 2016 by orbs Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
Jdr Posted August 19, 2016 Author Posted August 19, 2016 1 hour ago, Jos said: So you currently wait 100Ms (0.10 second) initially, then test for the file and then 150Msecs later you test it again? Jos Yes, I admit that's pretty fast, basically it's constantly checking for the file
Jdr Posted August 19, 2016 Author Posted August 19, 2016 1 hour ago, Jos said: So you currently wait 100Ms (0.10 second) initially, then test for the file and then 150Msecs later you test it again? Jos Yes, I admit that's pretty fast, basically it's constantly checking for the file
Jdr Posted August 19, 2016 Author Posted August 19, 2016 45 minutes ago, orbs said: if i get this right, then you need to play some animation while your script is waiting for the file to re-appear? well, you can delegate the animation to an external process, and make your waiting loop a lot simpler: ; create the animation While Not FileExists($sFile) Sleep(100) ; check for user clicking a cencellation button WEnd Yes, that's what happens. Won't "While Not" miss the beginning when the file is there? How can I get around that?
orbs Posted August 19, 2016 Posted August 19, 2016 (edited) 24 minutes ago, Jdr said: Won't "While Not" miss the beginning when the file is there? the real problem is that you have a single indication (the existence of a file) for two scenarios: before the process begins, and after the process ends. you better come up with a more precise distinction. you can, of course, do this: ; create the animation ; wait for first instance of the file to disappear While FileExists($sFile) Sleep(100) WEnd ; ok, the first instance disappeared. now wait for the second instance to appear While Not FileExists($sFile) Sleep(100) ; check for user clicking a cencellation button WEnd but, you must be absolutely sure that your script runs before the second instance appears! if you miss that, your script will hang at the 1st loop, and never reach to an end. Edited August 19, 2016 by orbs Signature - my forum contributions: Spoiler UDF: LFN - support for long file names (over 260 characters) InputImpose - impose valid characters in an input control TimeConvert - convert UTC to/from local time and/or reformat the string representation AMF - accept multiple files from Windows Explorer context menu DateDuration - literal description of the difference between given dates WinPose - simultaneous fluent move and resize Apps: Touch - set the "modified" timestamp of a file to current time Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes SPDiff - Single-Pane Text Diff Magic Math - a math puzzle Demos: Title Bar Menu - click the window title to pop-up a menu
aleph01 Posted August 20, 2016 Posted August 20, 2016 If, per Orbs, you have to be sure your script runs, you may be able to use ProcessExists in a couple of loops to wait for your process to start then stop, one to wait for the script to start running, one to wait for the script to finish. Meds. They're not just for breakfast anymore.
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