IfFileExists> Then run a program
Moderators: JRL, Dorian (MJT support)
IfFileExists> Then run a program
I am out of my depth here.
I think the principal command is "IfFileExists>" but I can't get it to do what I want (which is pretty much as below):
Test if file "File1.csv" exists, if FALSE run ABC.exe,
Test if file "File2.csv" exists, if FALSE run DEF.exe,
Test if file "File3.csv" exists, if FALSE run GHI.exe,
Test if file "File4.csv" exists, if FALSE run JKL.exe,
Pause for 1 hour
Run the 4 tests again (3 times)
If on the final run any of the files do not exist then leave a message on the screen identifying that there is a missing file (and if possible which one).
Thanks in advance for any suggestions that point me in the right direction.
Regards
k
I think the principal command is "IfFileExists>" but I can't get it to do what I want (which is pretty much as below):
Test if file "File1.csv" exists, if FALSE run ABC.exe,
Test if file "File2.csv" exists, if FALSE run DEF.exe,
Test if file "File3.csv" exists, if FALSE run GHI.exe,
Test if file "File4.csv" exists, if FALSE run JKL.exe,
Pause for 1 hour
Run the 4 tests again (3 times)
If on the final run any of the files do not exist then leave a message on the screen identifying that there is a missing file (and if possible which one).
Thanks in advance for any suggestions that point me in the right direction.
Regards
k
IfFileExists>
Hi Kriemer,
You may also want to consider OnEvent which can tell you the instant the filename comes into existence or is deleted/renamed.
But for now, the IfFileExists method.
Here is some untested script:
Hope this gets you started.
Gale
You may also want to consider OnEvent which can tell you the instant the filename comes into existence or is deleted/renamed.
But for now, the IfFileExists method.
Here is some untested script:
Code: Select all
//Loop thru filelist 4 times hourly.
Let>hourcounter=0
Let>Missing=Missing:%CRLF%
Repeat>hourcounter
Let>hourcounter=hourcounter+1
IfFileExists>File1.csv
//Do nothing
else
Let>Missing=%Missing%(%hourcounter%)File1.csv %CRLF%,
Run>ABC.EXE
end>
//Same thing for File2.csv
//Same thing for File3.csv
//Same thing for File4.csv
//wait 1 hour (3600 seconds)
wait>3600
Until>hourcounter>4
//Final message
MessageModal>%Missing%
Hope this gets you started.
Gale
I added the following code to close the message window each time the script is run, i.e., every 24 hours.
I found my original problem in running IfFileExists> was that I enclosed the path and file name in quotes. Doesn't work that way.
Thanks for the help.
k
Code: Select all
IfWindowOpen>Macro Scheduler Message
CloseWindow>Macro Scheduler Message
else
//Do nothing
endif>
****YOUR CODE****
Thanks for the help.
k
One way is something like this:
Code: Select all
Label>Start
///Whatever code
IfFileExists>File1.csv,,Start
IfFileExists>File2.csv,,Start
IfFileExists>File3.csv,,Start
IfFileExists>File4.csv,,Start
//Close script
Exit>0
JRL, et al;
I am at a loss as to how to integrate your code into what I have at this point. The purpose of the new code would be to end the script if all files are present. No message is necessary as all files exist (scripts have successfully completed).
This is the code as I'm currently working with it:
Thanks in advance.
k
I am at a loss as to how to integrate your code into what I have at this point. The purpose of the new code would be to end the script if all files are present. No message is necessary as all files exist (scripts have successfully completed).
This is the code as I'm currently working with it:
Code: Select all
DeleteFile>File1.csv - File4.csv
//Delete Message Window
IfWindowOpen>Macro Scheduler Message
CloseWindow>Macro Scheduler Message
else
//Do nothing
endif>
Let>hourcounter=0
Let>Missing=Missing:%CRLF%
Repeat>hourcounter
Let>hourcounter=hourcounter+1
IfFileExists>File1.csv
//Do nothing
else
Let>Missing=%Missing%(%hourcounter%)File1.csv %CRLF%,
Run>ABC.EXE
end>
//Same thing for File2.csv
//Same thing for File3.csv
//Same thing for File4.csv
/////This is what I'd like to do//////////////////////////////////
IfFileExists>FILE1.csv AND FILE2.csv AND FILE3.csv AND FILE4.csv
EXIT>
//////////////////////////////////////////////////////////////////
//Wait 1 hour (3600 seconds)
wait>3600
//Loop n times
Until>hourcounter>4
//Final message
MessageModal>%Missing%
k
Altered slightly and note the first comment.
Code: Select all
//Do you know that this will not delete the 4 files?
DeleteFile>File1.csv - File4.csv
//Delete Message Window
IfWindowOpen>Macro Scheduler Message
CloseWindow>Macro Scheduler Message
else
//Do nothing
endif>
Let>hourcounter=0
Let>Missing=Missing:%CRLF%
Repeat>hourcounter
Let>hourcounter=hourcounter+1
IfFileExists>File1.csv
//Do nothing
else
Let>Missing=%Missing%(%hourcounter%)File1.csv %CRLF%,
Run>ABC.EXE
end>
//Same thing for File2.csv
//Same thing for File3.csv
//Same thing for File4.csv
/////This is what I'd like to do//////////////////////////////////
IfFileExists>File1.csv,,Skip
IfFileExists>File2.csv,,Skip
IfFileExists>File3.csv,,Skip
IfFileExists>File4.csv,,Skip
EXIT>0
Label>Skip
//////////////////////////////////////////////////////////////////
//Wait 1 hour (3600 seconds)
wait>3600
//Loop n times
Until>hourcounter>4
//Final message
MessageModal>%Missing%
I suspected that was the case which is why I didn't rewrite it for you but I still had to ask . I don't know what you know or don't know.Yes I know it won't work as is, I was trying shorthand but apparently not very effectively (sigh).
First you need to understand how IfFileExists> works.Could you explain how the Label>skip code works? I'm confused.
From Help for IfFileExists>
All Macro Scheduler If> functions have two modes of operation. We either have a one line If> test with one or two labels, the first label is processed when the test is true, the second label (which is optional) is processed when the test is false. Or, If> can have a multi-line test where rather than jumping to labels, we can add any code in the If,Then,Else pattern.IfFileExists>filename[,label_name[,false_label_name]]
statements
[ [Else
else statements]
Endif ]
If filename exists the first statements are executed. Otherwise the else statements are executed.
In the example posted for you, we are using the one line method and jumping to labels.
So in the line:
IfFileExists>File1.csv,,Skip
If the file "file1.csv" exists the script jumps to the first label name specified. In the example line there is no first label name so in effect, the script does nothing. If the file "file1.csv" does not exist, the script jumps to the second label name which in the example is the "Skip" label. If the first file does not exist we go to label "Skip" then wait a hour before continuing. There is no need to check for the existance of the other files because we only want to know when all the files exist so as soon as one does not exist we can exit the test. If the first file exists we go to the second line and see if "File2.csv" exists. If it does not we "Skip" and wait an hour if it does we check for the existance of "File3.csv"..... and so on.
Hope this is helpful.
Is the Syntax OK
I am wondering if the syntax of the following code is correct. While everything appears to work, the editor highlighting makes me suspicious.
Yes, I only want to run the test on the second loop.
My thanks as always.
k
Code: Select all
***Do Some Stuff***
Let>loopcounter=0
Repeat>loopcounter
Let>loopcounter=loopcounter+1
//Exit Script If ALL Files Exist AFTER First Loop (1x)
if>loopcounter=2
IfFileExists>C:\Users\File1,,Skip
IfFileExists>C:\Users\File2,,Skip
IfFileExists>C:\Users\File3,,Skip
Exit>0
Label>Skip
else
//Do nothing
endif
***Do Somemore Stuff***
Until>loopcounter>3
My thanks as always.
k
Re: Is the Syntax OK
Hi kriemer,kriemer wrote: ***Do Some Stuff***
Let>loopcounter=0
Repeat>loopcounter
Let>loopcounter=loopcounter+1
//Exit Script If ALL Files Exist AFTER First Loop (1x)
if>loopcounter=2
IfFileExists>C:\Users\File1,,Skip
IfFileExists>C:\Users\File2,,Skip
IfFileExists>C:\Users\File3,,Skip
Exit>0
Label>Skip
else
//Do nothing
endif
***Do Somemore Stuff***
Until>loopcounter>3
I am wondering if the syntax of the following code is correct. While everything appears to work, the editor highlighting makes me suspicious.
Your code looks OK but you made me curious... so I pasted your code into the editor (MS version 11.1.19 on Windows 7) and the color syntax highlighting has an issue.
The endif and the first If> statement should be highlighted green similar to the above... but instead, it is fooled and pairs up the endif with the last of the three IfFileExists> lines. If the three IfFileExists> lines are deleted, color syntax highlighting works properly. Marcus, can you reproduce this problem?
Thanks for posting your suspicions kriemer.
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -

- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
John,
This has been discussed before - if you use "inline" ifs - i.e. a true/false label in the If command, which are deprecated, then it will confuse the syntax highlighter which expects an Endif.
There's no neat solution to this. Idealistically we'd remove support for inline if statements altogether.
This has been discussed before - if you use "inline" ifs - i.e. a true/false label in the If command, which are deprecated, then it will confuse the syntax highlighter which expects an Endif.
There's no neat solution to this. Idealistically we'd remove support for inline if statements altogether.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
Thanks Marcus... not looking for removal of support for inline if statements as that would break a lot of old code.mtettmar wrote:There's no neat solution to this. Idealistically we'd remove support for inline if statements altogether.
I guess this will just have to remain a known issue.
Hi kriemer,
If you want the syntax highlighting to look right, you could add an EndIf line along with each of your IfFileExists> lines as in the code below. No difference in how it operates... other than the color syntax highlighting.
Take care
Code: Select all
***Do Some Stuff***
Let>loopcounter=0
Repeat>loopcounter
Let>loopcounter=loopcounter+1
//Exit Script If ALL Files Exist AFTER First Loop (1x)
if>loopcounter=2
IfFileExists>C:\Users\File1,,Skip
EndIf
IfFileExists>C:\Users\File2,,Skip
EndIf
IfFileExists>C:\Users\File3,,Skip
EndIf
Exit>0
Label>Skip
else
//Do nothing
endif
***Do Somemore Stuff***
Until>loopcounter>3
jpuziano
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
Note: If anyone else on the planet would find the following useful...
[Open] PlayWav command that plays from embedded script data
...then please add your thoughts/support at the above post -
