JohnRichard Posted August 12, 2008 Posted August 12, 2008 hello fellow members. i have this script with checkbox option which backup certain folder in my computer (eg...dekstop, favorites, my documents. I got it working on some point. It has also a browse button to select a folder location for backup. However, i got stock with some conditions such that if i selected already a folder, but i did not select a file to backup, i want the script to give me message informing me that no file(s) were selected. Please need your advise...Here is my code #NoTrayIcon #include <GUIConstants.au3> #include <WindowsConstants.au3> #include <ButtonConstants.au3> #include <EditConstants.au3> #include <GuiEdit.au3> #include <File.au3> Global $path Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=C:\Documents and Settings\jyumul\Desktop\auTO3\samples\BackUp\Backup_new.kxf $Form1 = GUICreate("Backup", 491, 377, -1, -1) GUISetOnEvent($GUI_EVENT_CLOSE, "Form1Close") GUISetOnEvent($GUI_EVENT_MINIMIZE, "Form1Minimize") GUISetOnEvent($GUI_EVENT_MAXIMIZE, "Form1Maximize") GUISetOnEvent($GUI_EVENT_RESTORE, "Form1Restore") $Group1 = GUICtrlCreateGroup("Select Folder to Backup", 48, 75, 393, 126) $Documents_Checkbox = GUICtrlCreateCheckbox("My Documents", 72, 115, 97, 25) GUICtrlSetOnEvent($Documents_Checkbox, "Documents_CheckboxClick") $Favorites_Checkbox = GUICtrlCreateCheckbox("Favorites", 72, 157, 97, 25) GUICtrlSetOnEvent($Favorites_Checkbox, "Favorites_CheckboxClick") $Desktop_CheckBox = GUICtrlCreateCheckbox("Desktop", 310, 115, 97, 25) GUICtrlSetOnEvent($Desktop_CheckBox, "Desktop_CheckBoxClick") $Outlook_CheckBox = GUICtrlCreateCheckbox("MS Outlook", 310, 157, 97, 25) GUICtrlSetOnEvent($Outlook_CheckBox, "Outlook_CheckBoxClick") GUICtrlCreateGroup("", -99, -99, 1, 1) $Edit = GUICtrlCreateEdit("", 48, 240, 393, 65, $ES_READONLY) GUICtrlSetOnEvent(-1, "Change") GUICtrlSetData ($Edit, "Please select which file(s) to backup") $Backup_Button = GUICtrlCreateButton("Backup", 104, 328, 113, 33, 0) GUICtrlSetFont($Backup_Button, 8, 800, 0, "MS Sans Serif") GUICtrlSetOnEvent($Backup_Button, "Backup_Buttonclick") $Exit_Button = GUICtrlCreateButton("Exit", 276, 328, 113, 33, 0) GUICtrlSetFont($Exit_Button, 8, 800, 0, "MS Sans Serif") GUICtrlSetOnEvent($Exit_Button, "Exit_Buttonclick") $Backup_Label = GUICtrlCreateLabel("Backup Location:", 50, 26, 104, 17) GUICtrlSetFont($Backup_Label, 8, 800, 0, "MS Sans Serif") ;GUICtrlSetOnEvent($Backup_Label, "Backup_LabelClick") $Browse_Button = GUICtrlCreateButton("Browse", 351, 12, 89, 33, 0) GUICtrlSetFont($Browse_Button, 8, 800, 0, "MS Sans Serif") GUICtrlSetOnEvent($Browse_Button, "Browse_Buttonclick") $Input = GUICtrlCreateInput("", 160, 23, 185, 21) GUICtrlSetOnEvent(-1, "Change") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $Documents = GUICtrlRead($Documents_Checkbox) $Favorites = GUICtrlRead($Favorites_Checkbox) $Desktop = GUICtrlRead($Desktop_CheckBox) $Outlook = GUICtrlRead($Outlook_CheckBox) $Location = GUICtrlRead($Input) $Browse = GUICtrlRead($Browse_Button) $mainwindow = GUIGetMsg() Switch $mainwindow Case $GUI_EVENT_CLOSE Exit_Buttonclick() Case $Backup_Button Backup_Buttonclick() EndSwitch WEnd Func Backup_Buttonclick() Select Case $Location = GUICtrlRead($Input) If $Location = "" Then GUISetState(@SW_DISABLE, $Form1) $msg = MsgBox(16, "Location", "Please select location for your backup") If $msg = 1 Then GUISetState(@SW_ENABLE, $Form1) If $Favorites = $GUI_UNCHECKED Then MsgBox(16, "Files", "You did not select a files(s). Please select which file(s) you want to backup") ;GUICtrlSetData($Edit, "Please select which files(s) to backup") ;If $Favorites = $GUI_UNCHECKED And $Location <> "" Then ;MsgBox(16, "Location", "Please select which files(s) to backup") ;EndIf EndIf EndIf Endif EndSelect EndFunc Func Browse_Buttonclick() $path = FileSelectFolder("Choose folder for your backup", "", 1) GUICtrlSetData($Input, $path) EndFunc Func Change() EndFunc Func Desktop_CheckBoxClick() Local $desktop_path = @UserProfileDir & "\Desktop" Select Case $Desktop = GUICtrlRead($Desktop_CheckBox) If $Desktop = $GUI_CHECKED Then DirCreate($path & "\Desktop Backup") DirCopy($desktop_path, $path & "\Desktop Backup", 1) EndIf EndSelect EndFunc Func Documents_CheckboxClick() Local $my_documents = @MyDocumentsDir Local $Folder_Array = _FileListToArray($my_documents & "\", "*", 2) Select Case $Documents = GUICtrlRead($Documents_Checkbox) If $Documents = $GUI_CHECKED Then DirCreate($path & "\My Documents Backup") DirCopy($my_documents, $path & "\My Documents Backup") EndIf EndSelect EndFunc Func Exit_Buttonclick() Exit EndFunc Func Favorites_CheckboxClick() Local $Favorites_path = @UserProfileDir & "\Favorites" Select Case $Favorites = GUICtrlRead($Favorites_Checkbox) If $Favorites = $GUI_CHECKED Then GUICtrlSetData($Edit, "You selected Favorites Folder");& @CRLF DirCreate($path & "\Favorites Backup") $copy = DirCopy($Favorites_path, $path & "\Favorites Backup", 1) ;GUICtrlSetData($Edit, & @CRLF "You selected Favorites") EndIf EndSelect EndFunc Func Outlook_CheckBoxClick() EndFunc Func Form1Close() Exit EndFunc Func Form1Restore() EndFunc Func Form1Maximize() EndFunc Func Form1Minimize() EndFunc Func UnChecked() Select Case $Documents = GUICtrlRead($Documents_Checkbox) If $Documents = $GUI_UNCHECKED Then $msg1 = MsgBox(16, "Files", "Please select which files(s) to backup") ;GUICtrlSetData($Edit, "Please select which files(s) to backup") EndIf Case $Favorites = GUICtrlRead($Favorites_Checkbox) If $Favorites = $GUI_UNCHECKED Then GUICtrlSetData($Edit, "Please select which files(s) to backup") EndIf Case $Desktop = GUICtrlRead($Desktop_CheckBox) If $Desktop = $GUI_UNCHECKED Then GUICtrlSetData($Edit, "Please select which files(s) to backup") EndIf Case $Outlook = GUICtrlRead($Outlook_CheckBox) If $Outlook = $GUI_UNCHECKED Then GUICtrlSetData($Edit, "Please select which files(s) to backup") EndIf EndSelect EndFunc Func Backup1() GUICtrlSetData($Edit, "Please wait while data is being backup...." & @CRLF & @CRLF, 1) ;Desktop_CheckBoxClick() ;Favorites_CheckboxClick() GUICtrlSetData($Edit, "Backup is complete!" & @CRLF, 1) EndFunc
JohnRichard Posted August 12, 2008 Author Posted August 12, 2008 can please someone check my script.? coz i am starting to learn AUTOIT and my script gets more complicated to understand as i want to add more conditions on the script. i appreaciate all your help.
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