Jump to content


script help with if then statements

  • Please log in to reply
3 replies to this topic

#1 scubasteve1281



  • Active Members
  • 19 posts

Posted 29 September 2009 - 02:56 PM

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


#2 PsaltyDS


    Most Venerable Penguin

  • MVPs
  • 13,279 posts

Posted 29 September 2009 - 03:04 PM

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, 29 September 2009 - 03:04 PM.

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

#3 Mat


    43 38 48 31 30 4E 34 4F 32

  • MVPs
  • 5,096 posts

Posted 29 September 2009 - 03:06 PM

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, 29 September 2009 - 03:07 PM.

#4 scubasteve1281



  • Active Members
  • 19 posts

Posted 29 September 2009 - 03:30 PM

thanks I'll take a stab at it

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users