Sign in to follow this  
Followers 0
bigbangnet

mini backup script help request

11 posts in this topic

Before I begin, I'm a super noob when it comes to scripting and programming. I heard about Autoit on hak5 when they talked about it and I decided to give it a go. I mean, scripting seems a bit easier than C from what I heard so why not. Anyway, this is to tell you guys that this is the first time I am scripting in my life.

I decided to try out a small backup script. Pretty simple thing to do to start with. I want the script to display an input box and type in the source folder and the destination folder. then it copies the folder from 1 place to another. Later I will figure other things but I came to an halt. Here is the code first and you'll figure out the errors (the S in error should be a capital S hehe).

LOCAL $source = InputBox( "Source Folder", "Enter your source folder")
LOCAL $destination = InputBox("Source Folder", "Enter your destination folder")
If $source = @error = 1 Then
MsgBox(16, "Error", "Source doesn't exist")
DirCopy( $source,$destination,1)
Else
DirCopy( $source,$destination,1)
EndIf

I'm just starting to script and I know what the problem is but I don't know how to fix it. I know that in the first IF, the error displays after its asking the destination which doesn't make sense to me.

I just want the error to pop when the user enters the source and it doesn't exist. Same goes with destination. My question is how do I do that ?


** Warning **Noobie ahead. handle with caution

Share this post


Link to post
Share on other sites



Hi, bigbangnet, welcome to the forum. If you would like to mitigate the issue of the directory not existing, have a look at FileSelectFolder in the help file. You could do something simple like this to give your users a graphical representation to choose from, so they can SEE the folder rather than typing it in.

$init = FileSelectFolder("Select Backup Source", "C:", 7)

√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

bigbangnet,

Welcome to the AutoIt forum. :)

If you are as new to coding as you say, then reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page).

There are even video tutorials on YouTube if you prefer watching to reading.

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. :D

; ------------

Turning now to the script you posted. I would go about it in a different way: :)

; Start an infinite loop
While 1
    ; Get the source
    Local $source = InputBox("Source Folder", "Enter your source folder")
    If $source = "" Then
        ; if nothing was entered then say so and keep looping
        MsgBox(16, "Error", "Please enter a source")
    Else
        ; If we have a source we continue by starting a second infinite loop
        While 1
            ; get the destination
            Local $destination = InputBox("Destination Folder", "Enter your destination folder")
            If $destination = "" Then
                ; if we have no destination announce it
                MsgBox(16, "Error", "Please enter a destination")
            Else
                ; OK we have both - so exit both loops
                ExitLoop 2
            EndIf
        WEnd
    EndIf
WEnd
; And we only get here when we have both folders
MsgBox(0, "Success", "Source: " & $source & @CRLF & "Destination: " & $destination & @CRLF)

Please ask if you have any quesitons. ;)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

That works too. Guess I'm used to users that require visual aids :)


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

JLogan3o13,

I like your idea too. And it gives the OP a couple of options to choose from. :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Hi, bigbangnet, welcome to the forum. If you would like to mitigate the issue of the directory not existing, have a look at FileSelectFolder in the help file. You could do something simple like this to give your users a graphical representation to choose from, so they can SEE the folder rather than typing it in.

[ code='text' ] ( )

$init = FileSelectFolder("Select Backup Source", "C:", 7)

I can see with this method it would fix my problem once and for all. If the folder doesn't exist visually there is not way to select it. Thank for the help

bigbangnet,

Welcome to the AutoIt forum. :)

If you are as new to coding as you say, then reading the Help file (at least the first few sections - Using AutoIt, Tutorials and the first couple of References) will help you enormously. You should also look at the excellent tutorials that you will find here and here - you will find other tutorials in the Wiki (the link is at the top of the page).

There are even video tutorials on YouTube if you prefer watching to reading.

I know you want to start coding NOW, but a little study will save you a lot of trouble later on, believe me. :D

; ------------

Turning now to the script you posted. I would go about it in a different way: :)

; Start an infinite loop
While 1
    ; Get the source
    Local $source = InputBox("Source Folder", "Enter your source folder")
    If $source = "" Then
        ; if nothing was entered then say so and keep looping
        MsgBox(16, "Error", "Please enter a source")
    Else
        ; If we have a source we continue by starting a second infinite loop
        While 1
            ; get the destination
            Local $destination = InputBox("Destination Folder", "Enter your destination folder")
            If $destination = "" Then
                ; if we have no destination announce it
                MsgBox(16, "Error", "Please enter a destination")
            Else
                ; OK we have both - so exit both loops
                ExitLoop 2
            EndIf
        WEnd
    EndIf
WEnd
; And we only get here when we have both folders
MsgBox(0, "Success", "Source: " & $source & @CRLF & "Destination: " & $destination & @CRLF)

Please ask if you have any quesitons. ;)

M23

I'm looking at your code and I'm wondering. if the user enters abcd in the input field in either source or destination it seems like it will continue without errors. What i want to do is IF the folder doesn't exist then a msgbox opens up or an error message opens up saying it doesnt exist, please type one.

On a second note, i checked for @crlf and it seems like its a line break..I'm puzzle.

On a third note...yes I will check those tutorials lol. i need it but its not bad, i can understand most of your code Melba23

Edited by bigbangnet

** Warning **Noobie ahead. handle with caution

Share this post


Link to post
Share on other sites

bigbangnet,

Glad you can understand it. If you want to check the folder exists then you can use FileExists (it works for folders too) along these lines: :)

; Start an infinite loop
While 1
    ; Get the source
    Local $source = InputBox("Source Folder", "Enter your source folder")
    If $source = "" Then
        ; if nothing was entered then say so and keep looping
        MsgBox(16, "Error", "Please enter a source")
    Else
        ; If we have a source we check if it valid
        If FileExists($source) Then
            ; Continue by starting a second infinite loop
            While 1
                ; get the destination
                Local $destination = InputBox("Destination Folder", "Enter your destination folder")
                If $destination = "" Then
                    ; if we have no destination announce it
                    MsgBox(16, "Error", "Please enter a destination")
                Else
                    ; Check if valid
                    If FileExists($destination) Then
                        ; OK we have both - so exit both loops
                        ExitLoop 2
                    Else
                        MsgBox(0, "Error", "Path does not exist!")
                    EndIf
                EndIf
            WEnd
        Else
            MsgBox(0, "Error", "Path does not exist!")
        EndIf
    EndIf
WEnd
; And we only get here when we have both folders
MsgBox(0, "Success", "Source: " & $source & @CRLF & "Destination: " & $destination & @CRLF)

Can you follow that? Although I think JLogan3o13's solution might well prove the better. ;)

M23

P.S. Please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom when you do reply. Using the "Quote" button includes the text of the previous post and makes the thread difficult to follow. :D


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

I will go check the materials first before continuing. Something tells me I can't tell the user about the error before he even gives the destination folder but I will go read the pdf before saying no.

Thanks for the help

Edited by bigbangnet

** Warning **Noobie ahead. handle with caution

Share this post


Link to post
Share on other sites

bigbangnet,

I will go read the pdf

What pdf? :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

the link you provided brings me to a tutorial thread. that zip file in that thread contains a pdf. lol


** Warning **Noobie ahead. handle with caution

Share this post


Link to post
Share on other sites

bigbangnet,

Something tells me I can't tell the user about the error before he even gives the destination folder but I will go read the pdf before saying no

The tutorial is a tutorial - in the real world you can say "No" whenever you want! :)

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

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