Jump to content

List folders


Ezren1234
 Share

Recommended Posts

hello All,

i have been using Autoit for a while but just getting back into it again after a few years. i am creating a task to assist with my month end processes. i have a few folders that i am working with i have it kinda working but the only issue that i am running into is when i clicked on the folder i am always getting the same folder and sub folders displayed i am unsure how to switch between folders. below is the code i am using. it is working for Septembers folders and i am able to click on the sub folder and choose to Zip it and it starts but as i said i cant seem to get it to switch folders. thanks in advanced for help. sorry if i posted this in the wrong forum.

#Region ; GUI generated by GUIBuilderNxt Prototype 1.0

#include <Constants.au3>
#include <GUIConstantsEx.au3>
#include <Misc.au3>
#include <WindowsConstants.au3>
#include <ButtonConstants.au3>
#include <ListBoxConstants.au3>
#include <StaticConstants.au3>
#Include <Array.au3>
#Include <File.au3>
#Include <Zip.au3>

Global $MainStyle = BitOR($WS_OVERLAPPED, $WS_CAPTION, $WS_SYSMENU, $WS_VISIBLE, $WS_CLIPSIBLINGS, $WS_MINIMIZEBOX)

Global $hMain = GuiCreate("Month End Helper", 337, 321, -1, -1, $MainStyle)

Global $Button_1 = GuiCtrlCreateButton("List Contents", 20, 220, 120, 40)
;Global $Button_2 = GuiCtrlCreateButton("Zip", 180, 220, 120, 40)
Global $List_3 = GuiCtrlCreateList("", 10, 30, 140, 160)
Global $List_6 = GuiCtrlCreateList("", 170, 30, 140, 160)


GuiSetState(@SW_SHOWNORMAL)

While 1


 $GLOBE2 = "C:\Users\david.wa\Desktop\Month End\2019\OCT"
 $FileList3 = _FileListToArray($GLOBE2, "*.*", $FLTA_FOLDERS)

 $GLOBE3 = "C:\Users\david.wa\Desktop\Month End\2019\NOV"
 $FileList4 = _FileListToArray($GLOBE3, "*.*", $FLTA_FOLDERS)

 $GLOBE4 = "C:\Users\david.wa\Desktop\Month End\2019\DEC"
 $FileList5 = _FileListToArray($GLOBE4, "*.*", $FLTA_FOLDERS)
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button_1
            $sFolder = "C:\Users\david.wa\Desktop\Month End\2019\"
            Local $FileList = _FileListToArray($sFolder, "*.*", $FLTA_FOLDERS)

            If @error Then
                MsgBox(0, "", "No Folders Found.")

            EndIf


            For $i = 1 To $FileList[0]
                GUICtrlSetData($List_3, $FileList[$i])
             Next
        ; Case $Button_2
             ;ZIP()
          Case $List_3
             $GLOBE = "C:\Users\david.wa\Desktop\Month End\2019\SEPT"
            Local $FileList2 = _FileListToArray($GLOBE, "*.*", $FLTA_FOLDERS)
             If @error Then
                MsgBox(0, "", "No Folders Found.")
                Exit
            EndIf

            For $i = 1 To $FileList2[0]
                GUICtrlSetData($List_6, $FileList2[$i])
             Next
         Case $List_6
            _My_Func2()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd




Do
    Switch GuiGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case Else
            ;
    EndSwitch
 Until False

 

Link to comment
Share on other sites

Just now, Ezren1234 said:

...when i clicked on the folder i am always getting the same folder and sub folders displayed, i am unsure how to switch between folders...

Hello Ezren1234,
You need the $GLOBE variable to reflect the item selected in your list. Try to change this :

Case $List_3
    $GLOBE = "C:\Users\david.wa\Desktop\Month End\2019\SEPT"

by that :

Case $List_3
    $GLOBE = "C:\Users\david.wa\Desktop\Month End\2019\" & GUICtrlRead($List_3)

Now each time you select a month in the left panel ($List_3) it will display its subfolders in the right panel ($List_6) like in the following picture :

_GUICtrlListBox_ResetContent.png.d145edc73a59abc764fc7f952f3b22ce.png

Also, you need to blank $List_6 (right panel) each time something is gonna be displayed in it. 2 lines should do it :

#include <GuiListBox.au3> ; at the beginning of script
_GUICtrlListBox_ResetContent ($List_6) ; you sure will find where to place that line :)

Good luck :)

Edited by pixelsearch
Link to comment
Share on other sites

well now that you mention it i do need more help if possible.  i have it working for hte most part the only things left that i cant seem to figure out is when i click on the file in the list on the right side and the popup asked if i want to zip the file it zips the whole folder that the file is in and all i want is the file itself not the whole folder. i know its somewhere in the ZIP function but cant seem to figure out what i need to change.

#Region ; GUI generated by GUIBuilderNxt Prototype 1.0

#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <Misc.au3>
#Include <WindowsConstants.au3>
#Include <ButtonConstants.au3>
#Include <ListBoxConstants.au3>
#Include <StaticConstants.au3>
#Include <Array.au3>
#Include <File.au3>
#Include <Zip.au3>
#Include <GuiListBox.au3>

Global $MainStyle = BitOR($WS_OVERLAPPED, $WS_CAPTION, $WS_SYSMENU, $WS_VISIBLE, $WS_CLIPSIBLINGS, $WS_MINIMIZEBOX)

Global $hMain = GuiCreate("Month End Helper", 337, 321, -1, -1, $MainStyle)

Global $Button_1 = GuiCtrlCreateButton("List Contents", 20, 220, 120, 40)
;Global $Button_2 = GuiCtrlCreateButton("Zip", 180, 220, 120, 40)
Global $List_3 = GuiCtrlCreateList("", 10, 30, 140, 160)
Global $List_6 = GuiCtrlCreateList("", 170, 30, 140, 160)


GuiSetState(@SW_SHOWNORMAL)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button_1
            $sFolder = "C:\Users\david.wa\Desktop\Month End\2019\"
            Local $FileList = _FileListToArray($sFolder, "*.*", $FLTA_FOLDERS)

            If @error Then
                MsgBox(0, "", "No Folders Found.")

            EndIf


            For $i = 1 To $FileList[0]
                GUICtrlSetData($List_3, $FileList[$i])
             Next
        ; Case $Button_2
             ;ZIP()
          Case $List_3
            Folders()

         Case $List_6
            _My_Func2()
        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd




Do
    Switch GuiGetMsg()
        Case $GUI_EVENT_CLOSE
            ExitLoop

        Case Else
            ;
    EndSwitch
 Until False




Func ZIP()
    Dim $Zip, $myfile
$myfile = @DesktopDir & "\Month End\2019\" & GUICtrlRead($List_3)

$Zip = _Zip_Create(@DesktopDir & "\Month End\2019\ME.zip") ;Create The Zip File. Returns a Handle to the zip File
_Zip_AddFile($Zip,$myfile) ;add $myfile to the zip archive
;_Zip_AddFolder($Zip,@Desktopdir & "\Month End\2019\" & GUICtrlRead($List_3),4) ;Add a folder to the zip file (files/subfolders will be added)
;_Zip_AddFolderContents($Zip, @DesktopDir & "\Month End\2019\" & GUICtrlRead($List_3)) ;Add a folder's content in the zip file
MsgBox(0,"Items in Zip","there are " & _Zip_Count($Zip) & " items in " & $Zip) ;Msgbox Counting Items in $Zip
MsgBox(0,"Items in Zip","there are " & _Zip_CountAll($Zip) & " Elements in " & $Zip) ;Msgbox Counting Elements in $Zip

$search = _Zip_Search($Zip,"Test.txt") ;Returns an array containing the search results
For $i = 0 to UBound($search) - 1   ; Print Each
    ConsoleWrite($search[$i]) & @LF ; Corresponding value
Next                            ; In The Console

$list = _Zip_List($Zip) ;Returns an array containing all the files in the zip file
ConsoleWrite("============== ZIP Contents ============" & @LF)
For $i = 0 to UBound($list) - 1
    ConsoleWrite($list[$i] & @LF)   ;Print Search Results in the console
Next

Exit
EndFunc







Func _My_Func2()



Switch  MsgBox(4, "List Item", GUICtrlRead($List_6) & " Would you like to Zip File")

   Case $IDYES
      Call(ZIP())

EndSwitch


EndFunc

Func Folders()
   Local $GLOBE = "C:\Users\david.wa\Desktop\Month End\2019\" & GUICtrlRead($List_3)
_GUICtrlListBox_ResetContent ($List_6) ; you sure will find where to place that line :)

Select

     Case $GLOBE
      Local $FileList2 = _FileListToArray($GLOBE, "*.*", $FLTA_FOLDERS)
             If @error Then
                MsgBox(0, "", "No Folders Found.")
                Exit
            EndIf

            For $i = 1 To $FileList2[0]
                GUICtrlSetData($List_6, $FileList2[$i])

             Next

 EndSelect
EndFunc
#EndRegion

 

Link to comment
Share on other sites

Just now, Ezren1234 said:

...it zips the whole folder that the file is in and all i want is the file itself not the whole folder.

Hi Ezren,
This requires to change 1 line of your code :

; $myfile = @DesktopDir & "\Month End\2019\" & GUICtrlRead($List_3) ;add a whole folder's content

$myfile = @DesktopDir & "\Month End\2019\" & GUICtrlRead($List_3) & "\" & GUICtrlRead($List_6) ;add only a subfolder

Here is your script with the correct line to zip only the subfolder you check. I tested the result and it worked nicely... after I found Zip.au3 on the Web and recreated your folder structure :

#Include <Constants.au3>
#Include <GUIConstantsEx.au3>
#Include <Misc.au3>
#Include <WindowsConstants.au3>
#Include <ButtonConstants.au3>
#Include <ListBoxConstants.au3>
#Include <StaticConstants.au3>
#Include <Array.au3>
#Include <File.au3>
#Include <Zip.au3>
#Include <GuiListBox.au3>

Global $MainStyle = BitOR($WS_OVERLAPPED, $WS_CAPTION, $WS_SYSMENU, $WS_VISIBLE, $WS_CLIPSIBLINGS, $WS_MINIMIZEBOX)
Global $hMain = GuiCreate("Month End Helper", 337, 321, -1, -1, $MainStyle)
Global $Button_1 = GuiCtrlCreateButton("List Contents", 20, 220, 120, 40)
; Global $Button_2 = GuiCtrlCreateButton("Zip", 180, 220, 120, 40)
Global $List_3 = GuiCtrlCreateList("", 10, 30, 140, 160)
Global $List_6 = GuiCtrlCreateList("", 170, 30, 140, 160)

GuiSetState(@SW_SHOWNORMAL)

While 1
    $msg = GUIGetMsg()
    Switch $msg
        Case $Button_1
            $sFolder = "C:\Users\david.wa\Desktop\Month End\2019\"
            Local $FileList = _FileListToArray($sFolder, "*.*", $FLTA_FOLDERS)

            If @error Then
                MsgBox(0, "", "No Folders Found.")
            EndIf

            For $i = 1 To $FileList[0]
                GUICtrlSetData($List_3, $FileList[$i])
            Next

        ; Case $Button_2
        ;   ZIP()

        Case $List_3
            Folders()

        Case $List_6
            _My_Func2()

        Case $GUI_EVENT_CLOSE
            ExitLoop
    EndSwitch
WEnd

;============
Func Folders()
   Local $GLOBE = "C:\Users\david.wa\Desktop\Month End\2019\" & GUICtrlRead($List_3)
    _GUICtrlListBox_ResetContent ($List_6) ; you sure will find where to place that line :)

    Select
        Case $GLOBE
            Local $FileList2 = _FileListToArray($GLOBE, "*.*", $FLTA_FOLDERS)
            If @error Then
                MsgBox(0, "", "No Folders Found.")
                Exit
            EndIf

            For $i = 1 To $FileList2[0]
                GUICtrlSetData($List_6, $FileList2[$i])
            Next
    EndSelect
EndFunc

;============
Func _My_Func2()
    Switch  MsgBox(4, "List Item", GUICtrlRead($List_6) & " Would you like to Zip File")
        Case $IDYES
            ZIP()
    EndSwitch
EndFunc

;============
Func ZIP()
     Dim $Zip, $myfile

    ; $myfile = @DesktopDir & "\Month End\2019\" & GUICtrlRead($List_3) ;add a whole folder's content in the zip file
    $myfile = @DesktopDir & "\Month End\2019\" & GUICtrlRead($List_3) & "\" & GUICtrlRead($List_6) ;add only a subfolder

    $Zip = _Zip_Create(@DesktopDir & "\Month End\2019\ME.zip") ;Create The Zip File. Returns a Handle to the zip File

    _Zip_AddFile($Zip,$myfile) ;add $myfile to the zip archive
    MsgBox(0,"Items in Zip","there are " & _Zip_Count($Zip) & " items in " & $Zip) ;Msgbox Counting Items in $Zip
    MsgBox(0,"Items in Zip","there are " & _Zip_CountAll($Zip) & " Elements in " & $Zip) ;Msgbox Counting Elements in $Zip

    $search = _Zip_Search($Zip,"Test.txt") ;Returns an array containing the search results
    For $i = 0 to UBound($search) - 1   ; Print Each
        ConsoleWrite($search[$i] & @LF)  ; Corresponding value
    Next                            ; In The Console

    $list = _Zip_List($Zip) ;Returns an array containing all the files in the zip file
    ConsoleWrite("============== ZIP Contents ============" & @LF)
    For $i = 0 to UBound($list) - 1
        ConsoleWrite($list[$i] & @LF)   ;Print Search Results in the console
    Next

    Exit
EndFunc

Good luck :)

Edited by pixelsearch
Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...