Jump to content
Sign in to follow this  
sparker366

New project - Move Directories and Create New destination

Recommended Posts

Ok I have been having issues with the DirMove call. Its returning code 0 which is a failure. I am not sure why. This is just a code snippet from my full script. I didn't include the full script.

$iIndex = 0
MsgBox(0, "Move", "Move Directories")
$aDirectories = StringSplit($sSelection, @cr)
For $iIndex = 0 To $aDirectories[0] - 1
msgbox(0, "Directory Move", "Directory moving" & " " & $aDirectories[$iIndex])
FileWrite($File, $aDirectories[$iIndex])
$sret = DirMove($aDirectories[$iIndex], $sDestPath)
MsgBox(0, "Dir Move Code", $sret)
Next
FileClose($File)

Ignore the msgbox's as that is just for testing purposes and also am writing the paths out a file. For that life of me I can't figure out what the error is.I have the full path without trailing slash being passed to it. Here is the paths being past to it from the filewrite

e:\testing\SrcDir1
e:\testing\SrcDir10
e:\testing\SrcDir2
e:\testing\SrcDir3

The above is that paths getting passed to DirMove. Each directory has a text file it. The text files are empty but its still a file. They are valid and no trailing slash. I added the 1 to the end of the DirMove call and it moved the first directory then error out on the remaining directories. I have no idea what is going on here. I have checked everything to make sure the values of the paths are correct and they are.

At wits end on this one. Debugging with msgbox's is showing the correct path is getting passed to the DirMove function but its returning 0 which means it failed.

Edited by sparker366

Share this post


Link to post
Share on other sites

Your StringSplit is wrong for one thing, in Windows lines in a file are terminated with a CRLF, you're splitting on just the CR which leaves the LF at the end of each line. Try this, change the paths in this snippet to match your's.

$sDestPath = "C:\Temp"
MsgBox(0, "Move", "Move Directories")
$sSelection = FileRead(@ScriptDir & "\folders.txt")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sSelection = ' & $sSelection & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$aDirectories = StringSplit($sSelection, @CRLF, 1)
For $iIndex = 1 To $aDirectories[0] - 1
    MsgBox(0, "Directory Move", "Directory moving" & " " & $aDirectories[$iIndex])
    FileWrite($File, $aDirectories[$iIndex])
    $sret = DirMove($aDirectories[$iIndex], $sDestPath, 1)
    MsgBox(0, "Dir Move Code", $sret)
Next
FileClose($File)

BTW, it's easier to troubleshoot code if it is actually runnable.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Ok the stringsplit was the issue. The CR was causing the issue. Adding CRLF to it fixed it. Now another issue with my stringsplit was the flag. I see you used a 1 in yours and I omitted it. With doing that it added extra rows in the array thus causing dirmove failures. I added the 1 at the end an all is good.

Sorry what do you mean by this "BTW, it's easier to troubleshoot code if it is actually runnable." Do you mean I should compile it. That is just a snippet from the whole script. I usually just save it and use the beta run from the tools menu. When this goes production it will be an exe

Thanks for the help. I have no idea why I had the CR in there and not an CRLF. The script is working just fine. Oh I am going to be leaving the filewrtie in there as I need create a playlist for VideoLan of the paths and filenames so I can play them I just have to figure out that stage out later.

Again thanks for the input.

Edited by sparker366

Share this post


Link to post
Share on other sites

The code above wasn't runnable without modifying it first, which would cause some people to not make the effort to get it to run so they could see what was going wrong. No need to compile the scripts, just make them so that you copy the code from the post, run it and see where the problems are.

In case you're wondering what I meant by modifying the code above I meant, $sSelection isn't defined as to what it is supposed to be for, $destpath has a similar issue. Not a big deal, but you get more people willing to help if they can run it and troubleshoot the script.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

I edited that post to reflect that its just a code snippet from the full script. Not sure why I didn't state that.

I will get in the habit of posting full scripts from here going forward.

Again thanks for the help

Share this post


Link to post
Share on other sites

sparker366,

I will get in the habit of posting full scripts from here going forward

Not so fast! :D

You need to tread the difficult balance between providing too little code (which forces anyone helping to write a fair amount themselves to see what is going on) and posting an enormous script with lots of code which already works well and has no real bearing on the problem (which makes the potential helper sort through the whole code to find the problem). The best idea is to write a small reproducer script to show just the problem that you are having - and it is surprising how many times that sets off a "Eureka" moment when you find the solution to the problem for yourself. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

BrewManNH I tooked at your sample code and ran it. It worked fine except it only moved 9 of the 10 directories. I saw that was because of the -1 you put on the For Loop. Do I have to use the -1 on the For Loop? Won't that give me 1 short of what I want to move? I removed the -1 from that line and it moved all the directories in the source directory. I will cut and paste that working code into the main script when I get to that part again. This what I came up with and it works great. I just followed your example and tested it and it worked fine. I will just implement it in the full script removing the test information code.

$sDestPath = "e:\testing1"
Local $File = FileOpen($sDestPath & "test.txt", 1)
MsgBox(0, "Move", "Move Directories")
$sSelection = FileRead("d:\dirs.txt")
ConsoleWrite('@@ Debug(' & @ScriptLineNumber & ') : $sSelection = ' & $sSelection & @CRLF & '>Error code: ' & @error & @CRLF) ;### Debug Console
$aDirectories = StringSplit($sSelection, @CRLF, 1)
MsgBox(0, "Dir Count", $aDirectories[0])
For $iIndex = 1 To $aDirectories[0]
MsgBox(0, "Directory Move", "Directory moving" & " " & $aDirectories[$iIndex])
FileWrite($File, $aDirectories[$iIndex])
$sret = DirMove($aDirectories[$iIndex], $sDestPath, 1)
MsgBox(0, "Dir Move Code", $sret)
Next
FileClose($File)

I have totally screwed up my code. I recovered a viable source from a backup that was created.

I have add the code to populate the other ListView on the GUI. I want the left hand ListView (ListView1) to multi checkboxes and the right hand ListView (ListView2) to only allow a single checkbox. I have the following code to create the ListViews

Local $hListView1 = GUICtrlCreateListView("", 16, 64, 500, 400, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $LVS_NOCOLUMNHEADER), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
Local $hListView2 = GUICtrlCreateListView("", 536, 64, 500, 400, BitOR($LVS_SHOWSELALWAYS, $LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_SINGLESEL), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))

Now I think I figured it out. Since a checkbox is not a selection there is now way to limit that. Now I have changef ListView2 to a selection only ListView and kept ListView1 a checkbox one. Now I changed the below code to get the cheked boxes for loop 1 and the second loop only gets the item selected.

This is the code to check for the checked items. Its only a snippet of the full script.

$nMsg = GUIGetMsg()
$sSelection = _GUICtrlListView_GetSelectedIndices($hListView1)

Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
Case $nMsg = $btn1
$sSelection = ""
$iCount = 0
$iCount1 = 0
For $iIndex = 0 To $aArray[0] - 1
If _GUICtrlListView_GetItemChecked($hListView1, $iIndex) Then
$sItem &= _GUICtrlListView_GetItemText($hListView1, $iIndex) & @CRLF
$iCount += 1
EndIf
Next
$aItem = StringSplit($sItem, @CRLF, 1)
_ArrayDisplay($aItem1)

For $iIndex1 = 0 To $aArray1[0] - 1
If _GUICtrlListView_GetItemSelected($hListView2, $iIndex1) Then
$sItem1 &= _GUICtrlListView_GetItemText($hListView2, $iIndex1) & @CRLF
$iCount1 += 1
EndIf
Next
MsgBox(4160, "Information", "String Selected:" & " " & $sitem1)
MsgBox(4160, "Information", "Selected Count: " & $iCount & " $aArray[0]" & " " & $aArray[0])
MsgBox(4160, "Information", "Selected Count: " & $iCount1 & " $aArray1[0]" & " " & $aArray[0])
Case $nMsg = $btn2
MsgBox(0, "Move", "Move Directories")
Case $nMsg = $btn3
MsgBox(0, "Quit", "Quit")
Exit
EndSelect

The above code is now working to return an array of itmes checked and a string of the item selected. Now when I check 3 items in ListView1 and display the array of the checked items it display the following

[0]|4
[1]|e:\testing\SrcDir1
[2]|e:\testing\SrcDir10
[3]|e:\testing\SrcDir2
[4]|

This is showing me what you all have been telling me to do a -1 from the $aArray[0] value to get the correct amount of elements

I have no idea what is going on with my brain. Its not seeing things clearly. I did take a short break from this to try and clear it out but it seems that it did't work. I am just going to try and slow down and think more clearly and logically while doing this stuff.

Again thanks for everyone's help. I'll get this sorted out eventually. I will post back when I get the dirmove code working.

If you see anything that can be changed to make it more efficient please don't hesitate to suggest it.

Now If the destination directory doesn't exist I want the option of creating it. Hence the input box on the GUI. I guess I need to have routine that begins with _GUICtrlListView_BeginUpdate add the newly created directory to the list view close it with _GUICtrlListView_EndUpdate and then call _GUICtrlListView_RedrawItems to refresh it. Now _GUICtrlListView_RedrawItems requires a range from what I am seeing so I would use 0 to start then use _GUICtrlListView_GetItemCount to get me the total count of items and use that as the ending range for the RedrawItems function. So that should update the ListView

Edited by sparker366

Share this post


Link to post
Share on other sites

For my remove directory routine I need to update the ListView by removing the checked items as those will be moved and will no longer be a valid selection.

I saw in post 17 of this thread Melba23 put in some code to return the selected indices from the ListView. Well I implemented that code to create an array of the selected indices and the resultant array had a blank row at the start. It seems that the string is being created with a leading delimiter thus adding an extra row to the beginning of the array. I didn't see a way to stop that with code to check for checked items so I used a StringReplace call to remove the beginning delimiter and all is good now. I can't see a way to have that not put a leading delimiter in the string that it creates.

On to the next issue. _GUICtrlListView_DeleteItem will delete an item if you pass the index number to it. Well I selected 3 lines from the ListView and put those indices into an array. I then ran a For Loop to loop through that array and deleted the indices stored in it. Well I take a count of the ListView before and then a count after and it reflects the deleted items but the ListView Display is not updating correctly. Its only removing 1 item from the ListView Display. I need to have the ListView updated with the removed items. I can't seem to find anything to assist me with that. I thought about the redraw function and tried that but its not reflecting the removed items. How can I get it to reflect the removal of those items? I tried to redraw the ListView with the proper ending count and it still doesn't remove the deleted removed items from it. I searched on google for something and came up empty with regards to what I am trying to do.

Share this post


Link to post
Share on other sites

sparker366,

Personally I have always found it best to keep the ListView items in an array and completely rewrite the contents of the ListView each time the array is updated. But if you post the code you are using we can take a look. :)

As to the leading delimiter - why not just run the loop from 1 and not 0? Then you just miss out that first blank element. ;)

M23


Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png 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 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

Without a script showing what you're doing, it will be hard to come up with a solution for you.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Ok I just didn't want to get in the habit of posting my full script but here it is.

I used this script to create my testing directories Called it 2x's to create both directories.

;Create 2 directories and populate them with test files

Local $sSourcePath = "e:\testing\"
Local $sDestPath = "e:\testing1\"
Local $sSourceDir = "SrcDir"
Local $sDestDir = "DestDir"
Local $sFilename = "Test"
Local $sFileExt = ".txt"

;DirCreate($sDestPath & $sDestDir)

For $i = 1 To 10
FileOpen($sDestPath & $sDestDir & $i + 10 & "\" & $sFilename & $i + 10 & $sFileExt, 10)
FileClose($sFilename)
Next

Here is my code. Excuse the sloppiness of it and any inefficiencies in it. This is just testing code not the full code. Once I get the move directory code working I will implement that into the full script and then move on to the next stage.

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <RecFileListToArray.au3>
#include <File.au3>
#include <Array.au3>
Local $aRecords
Local $aArray
Local $aLVItems
Local $spath = "d:\Scripts-Programming\" ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $iItemCount
Local $sLVItems
;Get Test Data

$aArray = _RecFileListToArray($spath, "*", 2, 1, 1, 2)

;Create the GUI

Local $Form1_1 = GUICreate("Move files", 1058, 601, 192, 124)
Local $Label1 = GUICtrlCreateLabel("Source", 112, 32, 212, 17, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
Local $Label2 = GUICtrlCreateLabel("Destination", 696, 32, 212, 17, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
Local $btn1 = GUICtrlCreateButton("Delete Entries", 288, 544, 75, 25)
Local $btn2 = GUICtrlCreateButton("Move Dir", 440, 544, 75, 25)
Local $btn3 = GUICtrlCreateButton("Quit", 600, 544, 75, 25)
Local $hListView1 = GUICtrlCreateListView("", 16, 64, 500, 400, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
Local $hListView2 = GUICtrlCreateListView("", 536, 64, 500, 400, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_NOCOLUMNHEADER))
Local $Input1 = GUICtrlCreateInput("Input1", 336, 480, 329, 21)
GUISetState(@SW_SHOW)

;Main Script

_GUICtrlListView_InsertColumn($hListView1, 0, "Path", 900)
If IsArray($aArray) Then
For $i = 1 To $aArray[0]
_GUICtrlListView_AddItem($hListView1, $aArray[$i], $i)
Next
Else
MsgBox(0, "Error", "No Array Created")
EndIf

While 1
$nMsg = GUIGetMsg()
Select
Case $nMsg = $GUI_EVENT_CLOSE
Exit
Case $nMsg = $btn1
$sSelection = ""
$iCount = 0
For $iIndex = 0 To $aArray[0] - 1
If _GUICtrlListView_GetItemChecked($hListView1, $iIndex) Then
$sSelection &= "," & $iIndex +1
$iCount += 1
EndIf
$iItem = 0
Next
$sLVItems = StringReplace($sSelection, ",", "", 1)
$aLVItems = StringSplit($sLVItems, ",")
_ArrayDisplay($aLVItems)
MsgBox(4160, "Information", "Selected Indices: " & @CRLF & $sSelection)
MsgBox(4160, "Items Selected", "Items Selected: " & $iCount)
$iItemCount = _GUICtrlListView_GetItemCount($hListView1)
MsgBox(4160, "LV Item Count", "LV Item Count: " & $iItemCount)
_GUICtrlListView_BeginUpdate($hListView1)
For $iIndex = 1 to $aLVItems[0]
_GUICtrlListView_DeleteItem(GUICtrlGetHandle($hListView1), $aLVItems[$iIndex])
Next
_GUICtrlListView_EndUpdate($hListView1)
$iItemCount = _GUICtrlListView_GetItemCount($hListView1)
MsgBox(4160, "LV Item Count", "LV Item Count: " & $iItemCount)
_GUICtrlListView_RedrawItems($hListView1, 0, $iItemCount)
Case $nMsg = $btn2
MsgBox(0, "Move", "Move Directories")
Case $nMsg = $btn3
MsgBox(0, "Quit", "Quit")
Exit
EndSelect
WEnd

Melba so what you are saying is make a work array after calling your UDF. Then use the array created by your UDF to populate the ListView and then in the code to delete checked items remove those items out of the work array with a loop through the work array using this _ArrayDelete then redraw the ListView with the updated work array. If that's the solution it does sound like a viable one. Actually not sure why I am using that path in here it should be on of the testing directories I created with that small script. But it works for what I am doing as I am just testing the ListView updation after removing checked items.

Edited by sparker366

Share this post


Link to post
Share on other sites

Try this for deleting the items in the listview

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <GuiListView.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <RecFileListToArray.au3>
#include <File.au3>
#include <Array.au3>
Local $aRecords
Local $aArray
Local $aLVItems
Local $spath = "d:\Scripts-Programming\" ; <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
Local $iItemCount
Local $sLVItems
;Get Test Data
$aArray = _RecFileListToArray($spath, "*", 2, 1, 1, 2)
;Create the GUI
Local $Form1_1 = GUICreate("Move files", 1058, 601, 192, 124)
Local $Label1 = GUICtrlCreateLabel("Source", 112, 32, 212, 17, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
Local $Label2 = GUICtrlCreateLabel("Destination", 696, 32, 212, 17, $SS_CENTER)
GUICtrlSetFont(-1, 10, 800, 0, "MS Sans Serif")
Local $btn1 = GUICtrlCreateButton("Delete Entries", 288, 544, 75, 25)
Local $btn2 = GUICtrlCreateButton("Move Dir", 440, 544, 75, 25)
Local $btn3 = GUICtrlCreateButton("Quit", 600, 544, 75, 25)
Local $idListView1 = GUICtrlCreateListView("", 16, 64, 500, 400, BitOR($LVS_REPORT, $LVS_NOCOLUMNHEADER, $LVS_SHOWSELALWAYS), BitOR($WS_EX_CLIENTEDGE, $LVS_EX_CHECKBOXES, $LVS_EX_FULLROWSELECT))
; Get the handle to the control once, then you never have to do it again. Plus the UDFs work MUCH better when you're using handles and not Control IDs.
Global $hListView1 = GUICtrlGetHandle($idListView1) 
Local $idListView2 = GUICtrlCreateListView("", 536, 64, 500, 400, BitOR($GUI_SS_DEFAULT_LISTVIEW, $LVS_NOCOLUMNHEADER))
Global $hListView2 = GUICtrlGetHandle($idListView2)
Local $Input1 = GUICtrlCreateInput("Input1", 336, 480, 329, 21)
GUISetState(@SW_SHOW)
;Main Script
_GUICtrlListView_InsertColumn($hListView1, 0, "Path", 900)
If IsArray($aArray) Then
    For $i = 1 To $aArray[0]
        _GUICtrlListView_AddItem($hListView1, $aArray[$i], $i)
    Next
Else
    MsgBox(0, "Error", "No Array Created")
EndIf
While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $btn1
            $sSelection = ""
            $iCount = 0
            For $iIndex = 0 To $aArray[0] - 1
                If _GUICtrlListView_GetItemChecked($hListView1, $iIndex) Then
                    $sSelection &= $iIndex & "," ; ListView index starts at Zero, no need to add one, also puts the delimiter after the item index number
                    $iCount += 1
                EndIf
                $iItem = 0
            Next
            $sSelection = StringTrimRight($sSelection, 1) ; easier to code it this way
            $aLVItems = StringSplit($sSelection, ",")
            _ArrayDisplay($aLVItems)
            MsgBox(4160, "Information", "Selected Indices: " & @CRLF & $sSelection)
            MsgBox(4160, "Items Selected", "Items Selected: " & $iCount)
            $iItemCount = _GUICtrlListView_GetItemCount($hListView1)
            MsgBox(4160, "LV Item Count", "LV Item Count: " & $iItemCount)
            _GUICtrlListView_BeginUpdate($hListView1)
            For $iIndex = $aLVItems[0] To 1 Step -1 ; step through the items in reverse order, otherwise the indexes you're deleting are the wrong ones
                _GUICtrlListView_DeleteItem($hListView1, $aLVItems[$iIndex])
            Next
            _GUICtrlListView_EndUpdate($hListView1)
            $iItemCount = _GUICtrlListView_GetItemCount($hListView1)
            MsgBox(4160, "LV Item Count", "LV Item Count: " & $iItemCount)
;~          _GUICtrlListView_RedrawItems($hListView1, 0, $iItemCount) ; not sure if this is needed or not, doesn't seem to make any difference using it or not.
        Case $nMsg = $btn2
            MsgBox(0, "Move", "Move Directories")
        Case $nMsg = $btn3
            MsgBox(0, "Quit", "Quit")
            Exit
    EndSelect
WEnd


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

Why the reverse order for deleting the items? Yea the StringTrimRight is the key lots simpler. Not sure why I didn't think of that.

That doesn't seem something I could have figured out or found Very frustrating.

Now do I have to have the BeginUpdate and EndUpdate in there as well while doing the deletion from the list? I tried that with my script but it made no difference

Thanks for the help

Edited by sparker366

Share this post


Link to post
Share on other sites

Why the reverse order for deleting the items?

Here's why. Example, you want to delete items 1, 3, and 5. If you go and delete the first one (1), what was #2 on the list now becomes 1, and #3 becomes 2, #4 becomes 3. You now delete item 3, unfortunately, item 3 WAS item 4, so that gets deleted because you're telling it to delete the #3 item in the listview. The function has no way of knowing that everything was moved around in the list.

If you do it in reverse order, this isn't a problem because you're deleting things from higher up on the list. Delete #5, 3 is still in the same place, delete #3 and #1 is still in the same place.

Yea the StringTrimRight is the key lots simpler.

It makes it easier to see what you're doing with the statement.

Now do I have to have the BeginUpdate and EndUpdate in there as well while doing the deletion from the list? I tried that with my script but it made no difference

Thanks for the help

If you have a lot of items in your listview, using Begin/EndUpdate will make things go much faster because the listview isn't constantly being redrawn as you add/delete things from it.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

As an aside, unrelated directly but related tangentally. If you are deleting items from an array use the same method, delete the items in reverse order, because the same rules apply to items in the array.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

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  

×
×
  • Create New...