Jump to content

Logic Asistance


mr-es335
 Share

Go to solution Solved by Subz,

Recommended Posts

Good day,

I have a script that I have been using in a batch file, that I need to convert to AutoIt...and am having some difficulties.
• My main issues are in getting around the issue of NOT using GOTO!!

What i have here is the "logic" [I hope?!]...hat I am attempting to achieve...

Check if folder exists, if so, then continue
[goto continue]

If the folder does not exist, then say so, then...
[goto skipped1]

[continue]
If folder exists then attempt deletion
[delete folder?]

If the folder deletion was successful, then...
[goto skipped2]

If folder cannot be deleted then...
[goto log-off]

[skipped1]
[blah,  blah]
Exit

[skipped2]
[blah,  blah]
Exit

[log-off]
[blah,  blah]
[After log-on, repeat the above until sucessful]

The use of [log-off] I find is needed in that the application that I am attempting to delete has a single data file that does not permit deletion until a log-off is performed.

However, this issue should not really change the above "logic" in any whatsoever.

I have been attempting to use functions, but am getting lost in the weeds here!

Any assistance in this matter would be greatly appreciated!

Edited by mr-es335
Link to comment
Share on other sites

  • Solution

Basic example, untested.

;~ Folder Path
Local $sFolder = "C:\Folder"
;~ Check if folder exists
If FileExists($sFolder) Then
    ;~ Result is true, delete folder + files and subfolders
    Local $bDirRemove = DirRemove($sFolder, 1)
    ;~ Force logoff if the deletion was unsuccessful
    If $bDirRemove = False Then Shutdown(4)
    ;~ If folder deletion was successful then show msgbox and exit
    MsgBox(4096, "Result", "Folder Deleted Successfully")
    Exit
Else
    ;~ If the folder doesn't exist, msgbox and exit
    MsgBox(4096, "Result", "Folder does not exist")
    Exit
EndIf

 

Link to comment
Share on other sites

Subz,

So, I took your example, tried to understand the "logic" behind it...and then came up with the following:

First, the first iteration:

; -----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Uninstall_SAW()

Func Uninstall_SAW()
    Local $src_folder_saw = "C:\SAWStudio64Demo"
    ; -----------------
    DirRemove($src_folder_saw, $DIR_REMOVE)
EndFunc   ;==>Uninstall_SAW
; -----------------

Then the updated iteration:

; -----------------------------------------------
#include <AutoItConstants.au3>
#include <FileConstants.au3>
#include <FontConstants.au3>
#include <GUIConstantsEx.au3>
#include <MsgBoxConstants.au3>
; -----------------------------------------------
Uninstall_SAW()

Func Uninstall_SAW()
    Local $src_folder = "C:\SAWStudio64Demo"
    ; -----------------
    If FileExists($src_folder) Then
    Local $bDirRemove = DirRemove($src_folder, 1)
        If $bDirRemove = False Then Shutdown(0)
        ; -----------------
        MsgBox(4096, "Result", "Folder Deleted Successfully")
        Exit
    Else
        MsgBox(4096, "Result", "Folder does not exist")
        Exit
    EndIf
EndFunc   ;==>Uninstall_SAW
; -----------------------------------------------

Comparing your version to mine...this is what is observe:

[1] Check if folder exists
    [3] If folder exists then attempt deletion
    [5] If folder cannot be deleted then
    [8] [log-off]
[4] If the folder deletion was successful, then...
[2] If the folder does not exist then

This might take me a-moment-or-two to truly understand what you have done...!

Thanks for this, Subz...very much appreciated!

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...