Jump to content

Tidyer way of doing this?


Recommended Posts

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

  • Moderators

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

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

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)

NEWHeader1.png

Link to comment
Share on other sites

Thank you for your help. This is what i have done with it so far.

It is replacing my Startup folder

#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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...