Jump to content
Sign in to follow this  

script help with if then statements

Recommended Posts


I've recently started using AUTOIT. So far it has been pretty easy to figure out. I'm writing a new script that I'm trying to build some logic into using if then statements to look for a directory structure and if its not there create it, if it is then go onto the next part of the script. I'd really appreciate any help that could be given since Im pretty new at this

this my sudo code

look for folder C:\test If folder test exists then go on if not then create folder C:\test install app.exe

look for folder C:\test\testbaseline if folder C:\test\testbaseline exists then go on if not then create folder C:\test\testbaseline

look for folder C:\test\log if not the create folder C:\test\log

look for file C:\test\testbaseline\testbasline.txt if file exists then run app.exe with -c switch if not run app.exe

the output of app.exe will go to C:\test\testbaseline\testbasline.txt

the output of app.exe -c will go to C:\test\log and needs to be saved as a txt file (with the date time stamp of the time it was run).txt EX: log010109.txt

I want this to run through once if nothing is installed make all the folders copy app.exe to the folder and run the app.exe then go though make sure every thing is there then run the app.exe -c if every thing is there the first time through run the app.exe -c and quit

here is my lines of code so far

If FileExists("C:\test") do nothing if Not Then DirCreate("C:\test")

If FileExists("C:\test\app.exe")do nothing if Not Then FileInstall ("C:\windows\system32\app.exe" , "C:\test\app.exe")

If FileExists("C:\test\testbaseline")do nothing if Not Then DirCreate("C:\test\testbaseline")

If FileExists("C:\test\testbaseline\testbasline.txt) Then RunWait ("app.exe -c > C:\test\logs\ ;date time stamp I can do this in the command line here it will look something like %date:~10,4%%date:~4,2%%date:~7,2%.txt ", "")

; if the date time stamp can be done in autoit id like to do that but if its easier to do in the command line thats not a problem

If FileExists("C:\test\testbaseline\testbasline.txt) = no Then RunWait ("app.exe > C:\test\testbaseline\testbaseline.txt


Share this post

Link to post
Share on other sites

You don't have to specify what to do when the IF condition is not satisfied. Change the condition to detect what you want (i.e. directory doesn't exist):

If Not FileExists("C:\test") Then DirCreate("C:\test")

The date/time stamp can come from the macros (@YEAR, @MON, @MDAY, @HOUR, @MIN, @SEC) or just use _NowCalc() to get the string.

And welcome to AutoIt.


Edited by PsaltyDS

Valuater's AutoIt 1-2-3, Class... Is now in Session!For those who want somebody to write the script for them: RentACoder"Any technology distinguishable from magic is insufficiently advanced." -- Geek's corollary to Clarke's law

Share this post

Link to post
Share on other sites

The ifs are a mess, but theyre not far off!

If Not FileExists("C:\test") Then DirCreate("C:\test")
If Not FileExists("C:\test\app.exe") Then FileInstall ("C:\windows\system32\app.exe", "C:\test\app.exe")
If Not FileExists("C:\test\testbaseline") Then DirCreate("C:\test\testbaseline")
If FileExists("C:\test\testbaseline\testbasline.txt") Then FileWrite ("C:\test\log\" & @MDAY & "-" & @MON & "-" & @YEAR, "log text")
If Not FileExists("C:\test\testbaseline\testbasline.txt") Then RunWait ("app.exe > C:\test\testbaseline\testbaseline.txt")

The date can be done using the Date and time macros (see helpfle under "Macro Reference"). The reult above will give "29-9-2009", you will need to personalise that for yourself.

Edited by Mat

Share this post

Link to post
Share on other sites

thanks I'll take a stab at it

Share this post

Link to post
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
Sign in to follow this