happy2help Posted April 25, 2009 Share Posted April 25, 2009 Hi all I have several scripts which are similar to this one, which check for whether a file exists before trying to run it. I cannot use "if FileExists" on the same line as file i'm checking. #include <File.au3> #include "CustomMsgBox.au3" Opt("SendKeyDelay", 50) ;50 milliseconds Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info Opt("WinWaitDelay", 750) ;250 milliseconds If @compiled = 0 Then HotKeySet("{ESC}", "Exit1") Func Exit1() Exit EndFunc $f01 =$dir & $wash & " Dumped WE " & $today & ".pdf" $f02 =$dir2 & $cob & " Dumped WE " & $today & ".pdf" $f03 =$dir1 & $stan & " Dumped WE " & $today & ".pdf" $f04 =$dir3 & $wash & " DGS WE " & $today & ".xls" $f05 =$dir5 & $cob & " DGS WE " & $today & ".xls" $f06 =$dir4 & $stan & " DGS WE " & $today & ".xls" $f07 =$dir3 & $wash & " DGS WE " & $today & ".pdf" $f08 =$dir5 & $cob & " DGS WE " & $today & ".pdf" $f09 =$dir4 & $stan & " DGS WE " & $today & ".pdf" $f10 =$dir6 & "top 10 by dept we " & $today & ".pdf" $f11 =$p_c & "Product Changes Report-" & $today & ".pdf" $f12 =$p_c & "Price Changes Report-" & $today & ".pdf" Func monrun() If not FileExists($f01) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f01 & "Does NOT exists") If not FileExists($f02) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f02 & "Does NOT exists") If not FileExists($f03) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f03 & "Does NOT exists") If not FileExists($f04) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f04 & "Does NOT exists") If not FileExists($f05) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f05 & "Does NOT exists") If not FileExists($f06) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f06 & "Does NOT exists") If not FileExists($f07) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f07 & "Does NOT exists") If Not FileExists($f08) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f08 & "Does NOT exists") If Not FileExists($f09) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f09 & "Does NOT exists") If Not FileExists($f10) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f10 & "Does NOT exists") EndFunc is there a quicker or more efficient way of doing this. i'm sure i can use loops but i dont know how to make it check $f01 and then change the loop to check $f02, etc..etc.. thank you for any help you can give. Tony Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted April 25, 2009 Moderators Share Posted April 25, 2009 happy2help, Use an array for the filenames and then loop through them:Global $aFilenames[3] $aFilenames[0] = $dir & $wash & " Dumped WE " & $today & ".pdf" $aFilenames[1] =$dir2 & $cob & " Dumped WE " & $today & ".pdf" $aFilenames[2] =$dir1 & $stan & " Dumped WE " & $today & ".pdf" Func monrun() For $i = 0 To UBound($aFileNames) - 1 If not FileExists($aFileName[$i]) Then MsgBox(4096,"ALERT, ALERT, ALERT", $aFileName[$i] & "Does NOT exist") Next EndFunc You will, of course, have to adjust the size of the array to fit the number of files you wish to check. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Valuater Posted April 25, 2009 Share Posted April 25, 2009 NOT TESTED **** Global $f[13] $f[1] =$dir & $wash & " Dumped WE " & $today & ".pdf" $f[2] =$dir2 & $cob & " Dumped WE " & $today & ".pdf" $f[3] =$dir1 & $stan & " Dumped WE " & $today & ".pdf" $f[4] =$dir3 & $wash & " DGS WE " & $today & ".xls" $f[5] =$dir5 & $cob & " DGS WE " & $today & ".xls" $f[6] =$dir4 & $stan & " DGS WE " & $today & ".xls" $f[7] =$dir3 & $wash & " DGS WE " & $today & ".pdf" $f[8] =$dir5 & $cob & " DGS WE " & $today & ".pdf" $f[9] =$dir4 & $stan & " DGS WE " & $today & ".pdf" $f[10] =$dir6 & "top 10 by dept we " & $today & ".pdf" $f[11] =$p_c & "Product Changes Report-" & $today & ".pdf" $f[12] =$p_c & "Price Changes Report-" & $today & ".pdf" Func monrun() For $x = 1 to UBound($f) -1 If not FileExists($f[$x]) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f[$x] & "Does NOT exists", 10) Else ShellExecute($f[$x]) EndIf Next EndFunc 8) Link to comment Share on other sites More sharing options...
happy2help Posted April 25, 2009 Author Share Posted April 25, 2009 Thank you for your help. This is what i have done with it so far. It is replacing my Startup folder expandcollapse popup#ce ---------------------------------------------------------------------------- #include <File.au3> #include "CustomMsgBox.au3" #include <Misc.au3> #include "Busy.au3" Opt("SendKeyDelay", 50) ;50 milliseconds Opt("TrayIconDebug", 1) ;0=no info, 1=debug line info Opt("WinWaitDelay", 750) ;250 milliseconds If @compiled = 0 Then HotKeySet("{ESC}", "Exit1") Func Exit1() Exit EndFunc Global $f[13] Global $w[13] $pcent = 8 $f[1] ="C:\Program Files\Microsoft Office\Office12\OUTLOOK.EXE" $w[1] ="Outlook" $f[2] ="C:\Program Files\Mozilla Firefox\firefox.exe" $w[2] ="Fast Dial - Mozilla Firefox" $f[3] ="C:\Program Files\2BrightSparks\SyncBack\SyncBack.exe" $w[3] ="SyncBack" $f[4] ="C:\Users\Public\Backup\Batch files\Hotfolders.exe" $w[4] ="Hotfolders" $f[5] ="C:\Users\Public\Backup\Batch files\FolderCache\FolderCache.exe" $w[5] ="FolderCache" $f[6] ="C:\Users\Public\Backup\Batch files\auto_priority.exe" $w[6] ="auto_priority" $f[7] ="C:\Users\Public\Backup\DigiGuide TV Guide\client.exe" $w[7] ="DigiGuide TV Guide" $f[8] ="C:\Program Files\BBC Alerts\BBC_Alerts.exe" $w[8] ="BBC_Alerts" $f[9] ="C:\Program Files\BinarySense\HDDTemp4\HDDtemp4.exe" $w[9] ="HDDTemp4" $f[10] ="C:\Program Files\Nokia\Nokia PC Suite 7\PCSuite.exe" $w[10] ="Nokia PC Suite 7" $f[11] ="C:\Program Files\Windows Sidebar\sidebar.exe" $w[11] ="Windows Sidebar" $f[12] ="C:\Program Files\Windows Media Player\WMPNSCFG.exe" $w[12] ="Windows Media Player" For $x = 1 to UBound($f) -1 If not FileExists($f[$x]) Then MsgBox(4096,"ALERT, ALERT, ALERT", $f[$x] & "Does NOT exists", 10) Exit EndIf Next WinMinimizeAll ( ) $f[1] &=" /recycle" $f[3] &=" -m" Exit _Busy_Start() Sleep(1500) _Busy_UseTheme("Green") _Busy_Create($w[1], BitOR($BUSY_PROGRESS, $BUSY_SCREEN)) Run($f[1]) WinWait($w[1]) Sleep(5000) WinMinimizeAll ( ) _Busy_Update($w[2], $pcent) Run($f[2]) WinWait($w[2]) Sleep(5000) WinMinimizeAll ( ) For $x = 3 to UBound($f) -1 $pcent = $pcent + 8 _Busy_Update($w[$x], $pcent) Run($f[$x], "", @SW_MINIMIZE) Sleep(4000) Next _Busy_Update("Done", 100) Sleep(1000) _Busy_Close() _Busy_Stop() The machine seems to boot up much quicker now as it is now loading 1 prog at a time instead of 20 at the same time. Link to comment Share on other sites More sharing options...
Valuater Posted April 25, 2009 Share Posted April 25, 2009 Thank you for your help. This is what i have done with it so far....The machine seems to boot up much quicker now as it is now loading 1 prog at a time instead of 20 at the same time.Cool, Glad it helped!!8) 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