bigbangnet Posted January 17, 2012 Share Posted January 17, 2012 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 Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 17, 2012 Moderators Share Posted January 17, 2012 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) "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2012 Moderators Share Posted January 17, 2012 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. ; ------------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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Moderators JLogan3o13 Posted January 17, 2012 Moderators Share Posted January 17, 2012 That works too. Guess I'm used to users that require visual aids "Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball How to get your question answered on this forum! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2012 Moderators Share Posted January 17, 2012 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bigbangnet Posted January 17, 2012 Author Share Posted January 17, 2012 (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. ; ------------ 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 January 17, 2012 by bigbangnet ** Warning **Noobie ahead. handle with caution Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2012 Moderators Share Posted January 17, 2012 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. M23P.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. Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bigbangnet Posted January 17, 2012 Author Share Posted January 17, 2012 (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 January 17, 2012 by bigbangnet ** Warning **Noobie ahead. handle with caution Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 17, 2012 Moderators Share Posted January 17, 2012 bigbangnet,I will go read the pdfWhat pdf? M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
bigbangnet Posted January 18, 2012 Author Share Posted January 18, 2012 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 Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted January 18, 2012 Moderators Share Posted January 18, 2012 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 noThe 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 Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now