Sign in to follow this  
Followers 0
StOngeCompany

If Statements Within If Statements

6 posts in this topic

Hi AutoIt Forums,

I'm writing a script that copies files from a network location based on the username that is entered in. The problem I'm running into is that two of the files (the _pgp and _cui) are custom to each user. If the _pgp or _cui all ready exists on the user's machine, I want it to skip that step. If they do not all ready exist, I want them to be copied as usual.

I used an If...ElseIf...Else statement to copy files based on the username entered. Now I need to use ANOTHER If...Else statement to determine whther or not the _pgp or _cui all ready exist on the user's machine. Is there a way to use an If...Else statement INSIDE of an If...ElseIf...Else "master" statement?

Here is my script:

#cs ----------------------------------------------------------------------------

 AutoIt Version: 3.3.2.0
 Author:         DJ Berndt

 Script Function:
    Configure AutoCAD 2010 for SOCO use.

#ce ----------------------------------------------------------------------------

; Set Administrative Rights

#RequireAdmin
#AutoIt3Wrapper_res_requestedExecutionLevel=requireAdministrator

; Gather User Name

$username = InputBox("User Name", "Please enter your user name in the format of first initial last name.")

; John Melo

If $username = "jmelo" Then

; Create Directory

DirCreate("C:\Program Files\AutoCAD 2010\SOCO")

; Copy Directories

DirCopy("\\fileserver\media\Installs\SOCAD_r2010", "C:\Program Files\AutoCAD 2010\SOCO", 1)
FileCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad.lin", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
FileCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad.mnl", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
    If FileExists("C:\Program Files\AutoCAD 2010\SOCO\setup\support\melo_pgp") Then Sleep(1)
    Else
        DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\melo_pgp", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
    EndIf
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_lsp", "C:\Program Files\AutoCAD 2010\Support", 1)
    If FileExists("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\jmelo") Then Sleep(1)
    Else 
        DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\jmelo", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
    EndIf
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\ToolPalette")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\ToolPalette", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\ToolPalette", 1)
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\RegisteredTools")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\RegisteredTools", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\RegisteredTools", 1)
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\Profiles")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\Profiles", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\Profiles", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\plot styles", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Plot Styles", 1)

; Delete Files

FileDelete(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\acad.bak.cuix")
FileDelete(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\acad.mnr")

; Inform User of Completion

MsgBox(4096, "SOCO AutoCAD Installer", "SOCO AutoCAD installation complete!")



; Lee Detter

ElseIf $username = "ldetter" Then

; Create Directory

DirCreate("C:\Program Files\AutoCAD 2010\SOCO")

; Copy Directories

DirCopy("\\fileserver\media\Installs\SOCAD_r2010", "C:\Program Files\AutoCAD 2010\SOCO", 1)
FileCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad.lin", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
FileCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad.mnl", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
    If FileExists ("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_pgp") Then Sleep(1) 
    Else 
        DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_pgp", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_lsp", "C:\Program Files\AutoCAD 2010\Support", 1)
    If FileExists("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\ldetter") Then Sleep(1)
    Else 
        DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\ldetter", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
    EndIf
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\ToolPalette")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\ToolPalette", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\ToolPalette", 1)
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\RegisteredTools")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\RegisteredTools", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\RegisteredTools", 1)
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\Profiles")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\Profiles", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\Profiles", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\plot styles", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Plot Styles", 1)

; Delete Files

FileDelete(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\acad.bak.cuix")
FileDelete(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\acad.mnr")

; Inform User of Completion

MsgBox(4096, "SOCO AutoCAD Installer", "SOCO AutoCAD installation complete!")



; Matt Fidler

ElseIf $username = "mfidler" Then

; Create Directory

DirCreate("C:\Program Files\AutoCAD 2010\SOCO")

; Copy Directories

DirCopy("\\fileserver\media\Installs\SOCAD_r2010", "C:\Program Files\AutoCAD 2010\SOCO", 1)
FileCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad.lin", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
FileCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad.mnl", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_pgp", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_lsp", "C:\Program Files\AutoCAD 2010\Support", 1)
    If FileExists("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\mfidler") Then Sleep(1)
    Else 
        DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\mfidler", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
    EndIf
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\ToolPalette")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\ToolPalette", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\ToolPalette", 1)
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\RegisteredTools")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\RegisteredTools", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\RegisteredTools", 1)
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\Profiles")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\Profiles", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\Profiles", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\plot styles", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Plot Styles", 1)

; Delete Files

FileDelete(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\acad.bak.cuix")
FileDelete(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\acad.mnr")

; Inform User of Completion

MsgBox(4096, "SOCO AutoCAD Installer", "SOCO AutoCAD installation complete!")


; Nick Bauer

ElseIf $username = "nbauer" Then

; Create Directory

DirCreate("C:\Program Files\AutoCAD 2010\SOCO")

; Copy Directories

DirCopy("\\fileserver\media\Installs\SOCAD_r2010", "C:\Program Files\AutoCAD 2010\SOCO", 1)
FileCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad.lin", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
FileCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad.mnl", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_pgp", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_lsp", "C:\Program Files\AutoCAD 2010\Support", 1)
    If FileExists("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\nbauer") Then Sleep(1)
    Else 
        DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\nbauer", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
    EndIf
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\ToolPalette")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\ToolPalette", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\ToolPalette", 1)
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\RegisteredTools")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\RegisteredTools", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\RegisteredTools", 1)
DirRemove(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\Profiles")
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\Profiles", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\Profiles", 1)
DirCopy("C:\Program Files\AutoCAD 2010\SOCO\plot styles", @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Plot Styles", 1)

; Delete Files

FileDelete(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\acad.bak.cuix")
FileDelete(@AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support\acad.mnr")

; Inform User of Completion

MsgBox(4096, "SOCO AutoCAD Installer", "SOCO AutoCAD installation complete!")


Else 
    MsgBox(4096, "Error", "Invalid user name entered. Please enter a valid user name in the format of first initial last name.")
EndIf

I thank you very much for any and all assistance in advance.

Thanks,

StOngeCompany

Share this post


Link to post
Share on other sites



You can use multiple elseif. See this demo script

For $a = 1 To 6
    If $a = 1 Then
        ConsoleWrite("$a=1" & @CRLF)
    ElseIf $a = 2 Then
        ConsoleWrite("$a=2" & @CRLF)
    ElseIf $a = 3 Then
        ConsoleWrite("$a=3" & @CRLF)
    ElseIf $a = 4 Then
        ConsoleWrite("$a=4" & @CRLF)
    Else
        ConsoleWrite("$a>4" & @CRLF)
    EndIf
Next

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2017-04-18 - Version 1.4.8.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX (NEW 2017-02-27 - Version 1.3.1.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2015-04-01 - Version 0.4.0.0) - Download - General Help & Support - Example Scripts
Excel - Example Scripts - Wiki
Word - Wiki
PowerPoint (2015-06-06 - Version 0.0.5.0) - Download - General Help & Support

Tutorials:
ADO - Wiki

 

Share this post


Link to post
Share on other sites

Using the DirCopy you shouldn't have to use the FileExists.

DirCopy ( "source dir", "dest dir" [, flag] )

source dir = Path of the source directory (with no trailing backslash). e.g. "C:\Path1"

dest dir = Path of the desination dir (with no trailing backslash). e.g. "C:\Path_Copy"

flag = [optional] this flag determines whether to overwirte file if they already exist:

0 = (default) do not overwirte existing files

1 = overwirte existing files


If you try to fail and succeed which have you done?AutoIt Forum Search

Share this post


Link to post
Share on other sites

you sure can

$num = InputBox("enter a number", "1-5")
If $num < 1 Or $num > 5 Then
    MsgBox(0, "Error", "You entered a number that was not between 1 and 5", 3)
ElseIf $num > 0 And $num < 6 Then
    If $num > 0 And $num < 3 Then
        MsgBox(0, "Low Number", "You entered a low number of: " & $num, 3)
    ElseIf $num >= 3 And $num < 6 Then
        MsgBox(0, "High Number", "You entered a high number of: " & $num, 3)
    EndIf
EndIf

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

You might also consider looking at the "Switch...Case...EndSwitch " conditionals, since you're checking for specific usernames, and put the various Copy/Remove steps into a single function (using the username as a passed parameter) to eliminate code duplication.

Func SetupACAD($USERNAME)
   .. appropriate copy/remove steps here, such as:
   DirCopy("C:\Program Files\AutoCAD 2010\SOCO\setup\support\acad_cui\" & $USERNAME, @AppDataDir & "\AutoDesk\AutoCAD 2010\R18.0\enu\Support", 1)
EndFunc

Share this post


Link to post
Share on other sites

Using the DirCopy you shouldn't have to use the FileExists.

DirCopy ( "source dir", "dest dir" [, flag] )

source dir = Path of the source directory (with no trailing backslash). e.g. "C:\Path1"

dest dir = Path of the desination dir (with no trailing backslash). e.g. "C:\Path_Copy"

flag = [optional] this flag determines whether to overwirte file if they already exist:

0 = (default) do not overwirte existing files

1 = overwirte existing files

I can't believe I didn't think of that! I changed the _pgp and _cui copies to a flag or 0, and the script works like a charm. Thanks so much everyone!

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  
Followers 0