HTRN Posted May 6, 2019 Posted May 6, 2019 I have a script that opens a web browser, enters in an URL and thru API pulls down a CSV file. This is the first step in my script and once the file is downloaded I move it from downloads to another directory and do some other processing. If this file doesn't download I want to skip that whole section and move on to the next API Download. I can't offer a sample of my script, Its kinda proprietary but the jist is this.>> Heres what I do now. shellexecute("Chrome.exe" , "https://www.somedb.com/query?FILEXYX&datatype=csv Sleep(4999) IF FileExists("C:\Users\jsmith \Downloads\XYZ.csv") then ;Clear Dropbox for Today's csv processing. FileDelete ("\\dropbox\dropbox\backups\*.*") HOUSEKEEPINGSTEPS PROCESSING STEPS ELSE ;close chrome winactivate("Untitled - Google Chrome","") winwaitactive("Untitled - Google Chrome","") send ("!{f4}") WinWaitClose("Untitled - Google Chrome","","") ENDIF (Rinse and repeat with a different filename in the shell execute. I need to get rid of the Sleep(4999) and put in some code that looks for the file for 5 seconds. If it appears at anytime between 01-5000 miliseconds, immediately drop to the regular code after the THEN and process normally, or if it doesn't exist after 5 seconds, drop me down to the ELSE/ENDIF
Nine Posted May 6, 2019 Posted May 6, 2019 You could replace the blind ShellExecute (...) by an intelligent InetGet ( "URL", "filename", $options , $background), which gives a lot of information if used in background along with its good friend InetGetInfo ($handle). Take a look at those statements, I think you will like them... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
orbs Posted May 7, 2019 Posted May 7, 2019 (edited) @HTRN, welcome to AutoIt and to the forum. regarding simple file download, the suggestion above made by @Nine is good. for a more general-purpose approach, you can replace the Sleep() and the FileExists() condition with a call to a function like this: Func _FileExists_Timeout($sFile, $iTimeout) ; $iTimeout in milliseconds ; start counting time Local $hTimer = TimerInit() ; do stuff as long as the time count has not yet reached timout While TimerDiff($hTimer) < $iTimeout If FileExists($sFile) Then Return True ; check if the file exists Sleep(100) ; do not hog the CPU WEnd ; if you reached this point, it means the file does not exist after timeout Return False EndFunc ;==>_FileExists_Timeout read it carefully, look at the help file for TimerInit() and TimerDiff(). i have commented each line for you, but the code itself is quite simple. that function can be altered quite simply to match any process you need to check with time constraints. Edited May 7, 2019 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 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
Nine Posted May 7, 2019 Posted May 7, 2019 Instead of just checking if the file exists, I would suggest to use the InetGetInfo () options : $INET_DOWNLOADREAD / $INET_DOWNLOADSIZE to create a progress bar. That would make a high-quality UI especially for long downloads... “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Debug Messages Monitor UDF Screen Scraping Round Corner GUI UDF Multi-Threading Made Easy Interface Object based on Tag
HTRN Posted May 7, 2019 Author Posted May 7, 2019 Thank you both. I will let you know how it shakes out..
HTRN Posted May 7, 2019 Author Posted May 7, 2019 (edited) I appreciate the in depth information I get from InetGet ( "URL", "filename", $options , $background) but for this application which is run after hours on a PC as stand alone script, Orb's basic outline helped me build exactly what I needed. I simply plugged in the static data for the variables, plugged the returned "True" or "False" into my IF THEN ELSE statement and it works like a charm. Edited May 7, 2019 by HTRN
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