FBMC Posted November 3, 2009 Share Posted November 3, 2009 I am new to using AutoIt and am trying to create a program that transfers the selected files from a predefined location (Defined in an INI file) to a network location (also defined in the INI file) I have setup the GUI the way I want, but the problem is I am having a problem retrieving an array or something like that of all the checked items in the tree view. Basicly I am looking to do is have it copy the file from the source location to the destination location. expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <File.au3> #include <Array.au3> #Region ### START Koda GUI section ### $FBMCTransfer = GUICreate("FBMC Lockdown Transfer", 476, 601, 192, 122) $Transfer = GUICtrlCreateButton("Transfer", 400, 552, 67, 41, $WS_GROUP) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetCursor (-1, 0) $FolderList = GUICtrlCreateTreeView(8, 72, 461, 475, BitOR($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_DISABLEDRAGDROP,$TVS_SHOWSELALWAYS,$TVS_CHECKBOXES,$TVS_FULLROWSELECT,$WS_GROUP,$WS_TABSTOP,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER)) $InfoLabel = GUICtrlCreateLabel("Transfer folders below to:", 8, 8, 182, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $UFolder = GUICtrlCreateInput(@UserName, 160, 32, 113, 21) $ParentValue = IniRead( "C:\" & @UserName & "_Lockdown.ini", "Config", "Parent", "1") $Parent = GUICtrlCreateLabel($ParentValue, 16, 32, 142, 24, $SS_RIGHT) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $SubFolderValue = IniRead( "C:\" & @UserName & "_Lockdown.ini", "Config", "SubFolder", "1") $SubFolder = GUICtrlCreateLabel($SubFolderValue, 288, 32, 98, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $FolderListValue = IniRead( "C:\" & @UserName & "_Lockdown.ini", "Config", "Directory", "1") $FileList=_FileListToArray($FolderListValue, "*") Dim $FolderItem[999] For $i = 0 To $FileList[0] $filename = $FileList[$i] $FolderItem[$i] = GUICtrlCreateTreeViewItem($filename , $FolderList) Next $Progress = GUICtrlCreateProgress(16, 560, 374, 25) $Open = GUICtrlCreateButton("Open", 400, 32, 67, 25, $WS_GROUP) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetCursor (-1, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Open $UFolderValue = GUICtrlRead ($UFolder) $BrowseTo = $ParentValue & $UFolderValue & $SubFolderValue Run("explorer /e, " & '"' & $BrowseTo & '"') Case $Transfer $UFolderValue = GUICtrlRead ($UFolder) $Destination = $ParentValue & $UFolderValue & $SubFolderValue #######TRYING TO COPY EACH CHECKED FILE FROM EACH CHECKED FILE LOCATION TO THE $Destination######## EndSwitch WEnd And just so it's easy to use. Here's the program that is used to create the INI file. (Note, the close button doesn't work and I'm trying to figure that out too.) expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <StaticConstants.au3> #include <WindowsConstants.au3> Opt("GUIOnEventMode", 1) #Region ### START Koda GUI section ### Form=C:\Documents and Settings\dhand\Desktop\koda\Forms\TFATransferSetup.kxf $FBMCTransferSetup = GUICreate("FBMC Lockdown Transfer Setup", 361, 218, 203, 190) $ParentFolder = GUICtrlCreateInput("U:\", 144, 40, 193, 21) $SubFolder = GUICtrlCreateInput("\Foo\Bar\", 144, 72, 193, 21) $UserName = GUICtrlCreateInput("User Name", 144, 136, 193, 21) $ParentFolderLabel = GUICtrlCreateLabel("Parent Folder", 32, 40, 100, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $SubFolderLabel = GUICtrlCreateLabel("Sub Folder", 48, 72, 82, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $Title = GUICtrlCreateLabel("Configure Transfer utility INI File", 48, 0, 268, 28) GUICtrlSetFont(-1, 14, 400, 0, "MS Sans Serif") $UserNameLabel = GUICtrlCreateLabel("Setup for", 64, 136, 70, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $CreateINI = GUICtrlCreateButton("Create INI in User's Profile Folder", 152, 168, 179, 25, $WS_GROUP) GUICtrlSetOnEvent(-1, "CreateINIClick") $Directory = GUICtrlCreateInput("C:\Foo\Bar\", 144, 104, 193, 21) $DirectoryLabel = GUICtrlCreateLabel("Directory to List", 16, 104, 114, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 Sleep(100) WEnd Func CreateINIClick() $ParentFolderValue = GUICtrlRead ($ParentFolder) $DirectoryValue = GUICtrlRead ($Directory) $SubFolderValue = GUICtrlRead ($SubFolder) $UserNameValue = GUICtrlRead ($UserName) $Path = "C:\" & $UserNameValue & "_Lockdown.ini" IniWrite ( $Path, "Config", "Parent", $ParentFolderValue) IniWrite ( $Path, "Config", "SubFolder", $SubFolderValue) IniWrite ( $Path, "Config", "Directory", $DirectoryValue) IniWrite ( $Path, "Config", "Username", $UserNameValue) MsgBox(0,"Succes", "Created " & $Path) EndFunc Link to comment Share on other sites More sharing options...
Authenticity Posted November 3, 2009 Share Posted November 3, 2009 expandcollapse popup#include <ButtonConstants.au3> #include <EditConstants.au3> #include <GUIConstantsEx.au3> #include <ProgressConstants.au3> #include <StaticConstants.au3> #include <TreeViewConstants.au3> #include <WindowsConstants.au3> #include <GUITreeView.au3> #include <File.au3> #include <Array.au3> #Region ### START Koda GUI section ### $FBMCTransfer = GUICreate("FBMC Lockdown Transfer", 476, 601, 192, 122) $Transfer = GUICtrlCreateButton("Transfer", 400, 552, 67, 41, $WS_GROUP) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetCursor (-1, 0) $FolderList = GUICtrlCreateTreeView(8, 72, 461, 475, BitOR($TVS_HASBUTTONS,$TVS_HASLINES,$TVS_LINESATROOT,$TVS_DISABLEDRAGDROP,$TVS_SHOWSELALWAYS,$TVS_CHECKBOXES,$TVS_FULLROWSELECT,$WS_GROUP,$WS_TABSTOP,$WS_HSCROLL,$WS_VSCROLL,$WS_BORDER)) $InfoLabel = GUICtrlCreateLabel("Transfer folders below to:", 8, 8, 182, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $UFolder = GUICtrlCreateInput(@UserName, 160, 32, 113, 21) $ParentValue = IniRead( "C:\" & @UserName & "_Lockdown.ini", "Config", "Parent", "1") $Parent = GUICtrlCreateLabel($ParentValue, 16, 32, 142, 24, $SS_RIGHT) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $SubFolderValue = IniRead( "C:\" & @UserName & "_Lockdown.ini", "Config", "SubFolder", "1") $SubFolder = GUICtrlCreateLabel($SubFolderValue, 288, 32, 98, 24) GUICtrlSetFont(-1, 12, 400, 0, "MS Sans Serif") $FolderListValue = IniRead( "C:\" & @UserName & "_Lockdown.ini", "Config", "Directory", "1") $FileList=_FileListToArray($FolderListValue, "*") Dim $FolderItem[999] For $i = 0 To $FileList[0] $filename = $FileList[$i] $FolderItem[$i] = GUICtrlCreateTreeViewItem($filename , $FolderList) Next $Progress = GUICtrlCreateProgress(16, 560, 374, 25) $Open = GUICtrlCreateButton("Open", 400, 32, 67, 25, $WS_GROUP) GUICtrlSetFont(-1, 10, 400, 0, "MS Sans Serif") GUICtrlSetCursor (-1, 0) GUISetState(@SW_SHOW) #EndRegion ### END Koda GUI section ### While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $Open $UFolderValue = GUICtrlRead ($UFolder) $BrowseTo = $ParentValue & $UFolderValue & $SubFolderValue Run("explorer /e, " & '"' & $BrowseTo & '"') Case $Transfer $UFolderValue = GUICtrlRead ($UFolder) $Destination = $ParentValue & $UFolderValue & $SubFolderValue Local $aFiles = _GetCheckedItems($FolderList) If Not @error Then _ArrayDisplay($aFiles) EndSwitch WEnd Func _GetCheckedItems($hTreeView) Local $sItems = "", $hItem Local $aItems If Not IsHWnd($hTreeView) Then $hTreeView = GUICtrlGetHandle($hTreeView) If Not IsHWnd($hTreeView) Then Return SetError(1, 0, 0) If $Debug_TV Then _GUICtrlTreeView_ValidateClassName($hTreeView) $hItem = _GUICtrlTreeView_GetFirstItem($hTreeView) While $hItem If _GUICtrlTreeView_GetChecked($hTreeView, $hItem) Then $sItems &= _GUICtrlTreeView_GetText($hTreeView, $hItem) & '|' $hItem = _GUICtrlTreeView_GetNext($hTreeView, $hItem) WEnd $aItems = StringSplit(StringTrimRight($sItems, 1), '|') If @error Then Return SetError(2, 0, 0) Return $aItems EndFunc Look at the additional function. If the treeview contains nested items you'll need to preform the enumeration function as recursive, if you can find a good way to preform it using only loops. 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