Jump to content
youtuber

ListView move the selected file?

Recommended Posts

youtuber

I want to move the selected file
My problem is the following lines

Case $Button1
            For $s = 0 To _GUICtrlListView_GetItemCount($ListV1) - 1
                If _GUICtrlListView_GetItemChecked($ListV1, $s) Then
                    FileMove(@ScriptDir & "\" & $s, @DesktopDir & "\" & $s, $FC_OVERWRITE)
                EndIf
            Next

 

And all the codes

#include <ButtonConstants.au3>
#include <GUIConstantsEx.au3>
#include <ListViewConstants.au3>
#include <WindowsConstants.au3>
#include <File.au3>
#include <FileConstants.au3>
#include <GuiListView.au3>
Global $fTypes = "bmp|gif|png|jpg"
$Form1 = GUICreate("Form1", 259, 296, 192, 124)
$ListV1 = GUICtrlCreateListView("ListView 1", 32, 32, 186, 182, -1, BitOR($LVS_EX_CHECKBOXES, $WS_EX_CLIENTEDGE))
FindFiles()
$Button1 = GUICtrlCreateButton("Button1", 88, 232, 75, 25)
GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

        Case $Button1
            For $s = 0 To _GUICtrlListView_GetItemCount($ListV1) - 1
                If _GUICtrlListView_GetItemChecked($ListV1, $s) Then
                    FileMove(@ScriptDir & "\" & $s, @DesktopDir & "\" & $s, $FC_OVERWRITE)
                EndIf
            Next
            
    EndSwitch
WEnd

Func FindFiles($sType = "All Types")
    _GUICtrlListView_DeleteAllItems(GUICtrlGetHandle($ListV1))
    Local $ext = "*." & $sType, $FL2A
    If $sType = "All Types" Then $ext = "*.*"
    $FL2A = _FileListToArray(@ScriptDir, $ext, 1)
    If Not @error Then
        For $i = 1 To $FL2A[0]
            If $sType = "All Types" Then
                Local $SST = StringSplit($fTypes, "|")
                For $j = 1 To $SST[0]
                    If $SST[$j] = StringMid($FL2A[$i], StringInStr($FL2A[$i], ".", 0, -1) + 1) Then _
                            GUICtrlCreateListViewItem($FL2A[$i], $ListV1)
                Next
            ElseIf $sType <> "All Types" Then
                If $sType = StringMid($FL2A[$i], StringInStr($FL2A[$i], ".", 0, -1) + 1) Then _
                        GUICtrlCreateListViewItem($FL2A[$i], $ListV1)
            EndIf
        Next
        _GUICtrlListView_SetColumnWidth($ListV1, 0, $LVSCW_AUTOSIZE)
    EndIf
EndFunc   ;==>FindFiles

 

Share this post


Link to post
Share on other sites
BrewManNH

$s is a number, what exactly do you think is going to happen with that FileMove function call?

Don't you think you might need a GUICtrlRead, _GUICtrlListView_GetItemText or something similar in there somewhere?


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
youtuber

I think it should be something like this, but I have not been successful

For $s = 0 To _GUICtrlListView_GetItemCount($ListV1) - 1
                If _GUICtrlListView_GetItemChecked($ListV1, $s) Then
                    $SelectFile = GUICtrlRead(_GUICtrlListView_GetItemText($ListV1, $s))
                    FileMove(@ScriptDir & "\" & $SelectFile, @DesktopDir & "\" & $SelectFile, $FC_OVERWRITE)
                EndIf
            Next

 

Share this post


Link to post
Share on other sites
BrewManNH

I can imagine that it wouldn't work with that line. Try this

$SelectFile = _GUICtrlListView_GetItemText($ListV1, $s)

 

  • Like 1

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
youtuber

@BrewManNH Thank you, I can not make more than one File move
do you have a suggestion for it?

Share this post


Link to post
Share on other sites
BrewManNH

If there's more than one checked, that should move them one at a time.


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
BrewManNH

FileMove will only work with one file at a time unless you use wildcards, which won't work here. All of the other functions like it, FileCopy DirCopy etc., will have the same limitations.


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
BrewManNH
16 hours ago, BrewManNH said:

FileMove will only work with one file at a time unless you use wildcards, which won't work here.

I thought I was clear here.


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

×