rgbyte Posted June 11, 2014 Share Posted June 11, 2014 Hello. I am trying to create a script that will copy the files from a folder on a thumb drive (that the exe is on) to a drive (in this case it is always the H: Drive). Below is my script draft. I have a message box for directions, and I have a list of classes show up. Depending on the class, I want a different file copied, for this draft I was trying to make it easy and just copy everything in the directory (still only the 5 files) regardless of the class. When I tried it using the following, it wouldn't copy anything. I am somewhat new to Autoit, so any help would be appreciated. Also, a more general question about how it works, When I had it print a message box of the choice for the class, it started at 5 and not 0 or 1, is there a reason anyone can think of? Thanks ~>RGByte expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> MsgBox(0, "Statue Of Liberty", "Please select which class you are in and then press OK.") Statue() Func Statue() Global $hGUI = GUICreate("Statue of Liberty", 400, 400) Global $button = GUICtrlCreateButton("OK",20,175,150) Global $idListview = GUICtrlCreateListView("Class ||", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING) Global $idDesgeo1 = GUICtrlCreateListViewItem("Descriptive Geo", $idListview) Global $idDesgeo2 = GUICtrlCreateListViewItem("Physics", $idListview) Global $idDesgeo3 = GUICtrlCreateListViewItem("10th Grade Tables", $idListview) Global $idDesgeo4 = GUICtrlCreateListViewItem("10th Grade Computers", $idListview) Global $idDesgeo5 = GUICtrlCreateListViewItem("Architecture", $idListview) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $button DirCopy( "G:\Testfolder", "H:\") GUIDelete ("Statue of Liberty") EndSwitch WEnd EndFunc Link to comment Share on other sites More sharing options...
Jfish Posted June 12, 2014 Share Posted June 12, 2014 Is your USB drive always "G"? and is there definitely an "H" on the target machine? I would add some error checking like consolewrite(@scriptdir) to see what the directory is for the script on the USB. Also, the default is to no overwrite existing files - not sure if that is a requirement - if so you need to set that flag. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
Solution ZombieKillz Posted June 12, 2014 Solution Share Posted June 12, 2014 rgbyte, My guess as to why you were shown a 5 when printing your Class selection is perhaps you were printing $idListview which would show the controlid of the listview and not your selection (without seeing your message box code, of course). I commented the code below and hope it makes sense. You could either build your 'If' statements, to copy files for that particular Class selected, around the $indexselected (0-4 in this case) or around the $listtext or Class selected. Those variables are random and could be changed to anything you'd like. expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; added for extended features when dealing with listview MsgBox(0, "Statue Of Liberty", "Please select which class you are in and then press OK.") Statue() Func Statue() Global $hGUI = GUICreate("Statue of Liberty", 400, 400) Global $button = GUICtrlCreateButton("OK",20,175,150) Global $idListview = GUICtrlCreateListView("Class ", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING) Global $idDesgeo1 = GUICtrlCreateListViewItem("Descriptive Geo", $idListview) Global $idDesgeo2 = GUICtrlCreateListViewItem("Physics", $idListview) Global $idDesgeo3 = GUICtrlCreateListViewItem("10th Grade Tables", $idListview) Global $idDesgeo4 = GUICtrlCreateListViewItem("10th Grade Computers", $idListview) Global $idDesgeo5 = GUICtrlCreateListViewItem("Architecture", $idListview) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $button ; your original code - START ;DirCopy( "G:\Testfolder", "H:\") ;GUIDelete ("Statue of Liberty") ; your original code - END ; get the index from the selection made above $indexselected = _GUICtrlListView_GetSelectedIndices($idListview, False) ; now get the text associated with the selection using the indexselected variable ; note: have to change indexselected to a number in order for it to work correctly $listtext = _GUICtrlListView_GetItemTextString($idListview, Number($indexselected)) MsgBox(0,"Text from selection made", $listtext) EndSwitch WEnd EndFunc Link to comment Share on other sites More sharing options...
rgbyte Posted June 12, 2014 Author Share Posted June 12, 2014 Thanks ZombieKillz, that was exactly what I was looking for! Jfish, the thumb drive may change, but the drive I am copying to is always H:. Link to comment Share on other sites More sharing options...
ZombieKillz Posted June 12, 2014 Share Posted June 12, 2014 No problem, rgbyte. Glad that worked out for you. Link to comment Share on other sites More sharing options...
Jfish Posted June 12, 2014 Share Posted June 12, 2014 Jfish, the thumb drive may change, but the drive I am copying to is always H:. Then you may want to use @scriptdir for the "from" thumb drive part Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
rgbyte Posted June 13, 2014 Author Share Posted June 13, 2014 Global $copysuccess = DirCopy(@ScriptDir & "\Test",@ScriptDir & "\Test2") I tried using the above script to copy everything in my Test folder in the same directory as the script that runs and copy it to another folder in the same directory (for easy of debugging). The problem being that I have not been able to copy the 5 files in Test to Test2. The above line of code goes where the MsgBox(0,"Text from selection made", $listtext) was in ZombieKillz's script. The probelm is that it won't copy anything!!! Is there a problem in the script at top? I have seen examples where people appendage the @scriptdir macro with a sub folder. The idea here is that I don't want the students to copy the compiled exe too. Thanks. Link to comment Share on other sites More sharing options...
Jfish Posted June 13, 2014 Share Posted June 13, 2014 Do both folders "Test" and "Test2" appear in the same directory as your script? Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt Link to comment Share on other sites More sharing options...
ZombieKillz Posted June 13, 2014 Share Posted June 13, 2014 rgbyte, Can you also provide this new section of script you are trying to work out? Without revealing any proprietary info of course. - Mike Link to comment Share on other sites More sharing options...
rgbyte Posted June 13, 2014 Author Share Posted June 13, 2014 The two test folders are in the script's directory. (The path is AutoitfilesTest, or AutoitfilesTest2, and the script is in the Autoitfiles directory). The code is really similar. Whenever I try this it doesn't copy. Thanks expandcollapse popup#cs ---------------------------------------------------------------------------- AutoIt Version: 3.3.12.0 Author: myName Script Function: Template AutoIt script. #ce ---------------------------------------------------------------------------- ; Script Start - Add your code below here #include <FileConstants.au3> #include <GUIConstantsEx.au3> #include <MsgBoxConstants.au3> #include <WindowsConstants.au3> #include <GuiListView.au3> ; added for extended features when dealing with listview MsgBox(0, "Statue Of Liberty", "Please select which class you are in and then press OK.") Statue() Func Statue() Global $hGUI = GUICreate("Statue of Liberty", 400, 400) Global $button = GUICtrlCreateButton("OK",20,175,150) Global $idListview = GUICtrlCreateListView("Class", 10, 10, 200, 150) ;,$LVS_SORTDESCENDING) Global $idDesgeo1 = GUICtrlCreateListViewItem("Descriptive Geo", $idListview) Global $idDesgeo2 = GUICtrlCreateListViewItem("Physics", $idListview) Global $idDesgeo3 = GUICtrlCreateListViewItem("10th Tables", $idListview) Global $idDesgeo4 = GUICtrlCreateListViewItem("10th 2D/3D", $idListview) Global $idDesgeo5 = GUICtrlCreateListViewItem("Architecture", $idListview) GUISetState(@SW_SHOW) While 1 Switch GUIGetMsg() Case $GUI_EVENT_CLOSE ExitLoop Case $button ; get the index from the selection made above $indexselected = _GUICtrlListView_GetSelectedIndices($idListview, False) ; now get the text associated with the selection using the indexselected variable ; note: have to change indexselected to a number in order for it to work correctly $listtext = _GUICtrlListView_GetItemTextString($idListview, Number($indexselected)) If $indexselected = 0 Then Global $copysuccess=DirCopy(@ScriptDir & "\Test",@ScriptDir & "\Test2") ExitLoop EndIf EndSwitch WEnd EndFunc Link to comment Share on other sites More sharing options...
Jfish Posted June 14, 2014 Share Posted June 14, 2014 I think the issue may be the overwrite flag ... it works when I set that to "1". I a, not sure why but I think because the folders are at the same directory level it is considered an overwrite? You might consider file move instead to potentially avoid this. Build your own poker game with AutoIt: pokerlogic.au3 | Learn To Program Using FREE Tools with AutoIt 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