Sign in to follow this  
Followers 0
RosarioC

Looping through files and creating treeview items based on file count

8 posts in this topic

Hello, i'm back, don't worry i was coding in AutoIt, was just trying to teach my self with out sounding like an annoying noob like i did that first time, but this time i seem to be stuck on 2 things i'm trying to do in my scripts. been trying everything i can think of to get this to work so hopefully you can help me out, i gotta say i love this scripting lanquage!! anyways, here is my script.

Encryption.au3:

#include <ComboConstants.au3>

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiComboBox.au3>
#include <WinAPI.au3>
#include <GuiTreeView.au3>
#include <Debug.au3>



; These is the include files we need for this script to do what we want.
#Region ### START Koda GUI section ### Form=c:\users\ro\documents\autoitscripts\encryption\archive.kxf
$Archive = GUICreate("Archive Format v1.0", 579, 386, 198, 144)
GUISetIcon("C:\Program Files\WinRAR\WinRAR.exe", -1)
$Group1 = GUICtrlCreateGroup("Custom Archive Format", 8, 8, 561, 369)
$Pic1 = GUICtrlCreatePic("C:\Users\RO\Documents\AutoITscripts\Encryption\Images\Marcus.gif", 16, 32, 293, 241)
$Button1 = GUICtrlCreateButton("Add Files to Archive (.arch)", 360, 296, 161, 25)
$Browse = GUICtrlCreateButton("....", 528, 296, 33, 25)
;$FileView = _GUICtrlTreeView_Create($Archive, 344, 32, 209, 241, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_EDITLABELS, $TVS_NOTOOLTIPS, $TVS_CHECKBOXES, $TVS_TRACKSELECT, $TVS_INFOTIP, $TVS_FULLROWSELECT, $TVS_NONEVENHEIGHT, $WS_BORDER))

GUICtrlCreateGroup("", -99, -99, 1, 1)
GUISetState(@SW_SHOW)
;$File = CreateArchFile()

Global $DefaultFileName = "Untitled"
Global $File = 1
Global $ArraySize = 10000000
Dim $FileFormat
Global $ComboBox2
Global $CurSel, $hImage, $iImage

$TreeParent = _GUICtrlTreeView_Create($Archive, 344, 32, 209, 241, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_EDITLABELS, $TVS_NOTOOLTIPS, $TVS_CHECKBOXES, $TVS_TRACKSELECT, $TVS_INFOTIP, $TVS_FULLROWSELECT, $TVS_NONEVENHEIGHT, $WS_BORDER))
_DebugSetup("TreeView", True)
While 1

    #cs _GUICtrlComboBox_BeginUpdate($ComboBox2)
        _GUICtrlComboBox_DeleteString($ComboBox2,0)
        _GUICtrlComboBox_DeleteString($ComboBox2,1)
        $CurSel = _GUICtrlComboBox_GetCurSel($ComboBox2)
        _GUICtrlComboBox_EndUpdate($ComboBox2)
        MsgBox(0,"selected:" , "" & $CurSel)
    #ce

    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit

        Case $nMsg = $Browse
            $FileFormat = FileOpenDialog("Browse for files to encode", @WorkingDir, "Any File (*.*)", 4)
            For $x In $FileFormat
                $File = FileOpen($FileFormat, 0)
            Next
            _GUICtrlTreeView_BeginUpdate($TreeParent)
            For $x In $FileFormat
                ;$iImage = Random(0, 5, 1)
                $hItem = _GUICtrlTreeView_Add($TreeParent, 0, StringFormat("[%02d] New Item", $x)) ;$iImage, $iImage)
                For $y In $FileFormat
                    ;$iImage = Random(0, 5, 1)
                    _GUICtrlTreeView_AddChild($TreeParent, $hItem, StringFormat("[%02d] New Child", $y)); $iImage, $iImage)
                Next
            Next
            _GUICtrlTreeView_EndUpdate($TreeParent)

            _DebugOut("What??", True)
    EndSelect
WEnd

The output the consolse gives me:

C:\Users\<user>\Documents\AutoITscripts\Encryption\Encrypt.au3 (77) : ==> Variable must be of type "Object".:
For $x In $FileFormat
hope you can set me straight by the way, how would you check for just a certain type of format? like say i just wanted to add images to a certain treeview parents, would i have to check all the files even made in one huge code block? or is there a way to get the index of the combo box for the FileOpen? (Tried to usr AutoIt window tool to get info from it, nothing. like you know what i mean by checking the extension? i would figure an array in the FileOpen function but i'm not sure i think i tried it and it didn't work.

Share this post


Link to post
Share on other sites



From what I can see you want to create a tree view like so:

+ JPG

| + File 1.jpg

| + File 2.jpg

| + File 3.jpg

+ AU3

| + Something.au3

| + test.au3

+ EXT

| + File.EXT

Am I right?

FileOpenDialog only returns the full path of the file(s) chosen. Results for multiple selections are "Directory|file1|file2|...". Use StringSplit to turn it into an array.

Also, a simple for loop should suffice for your purpose. The way your doing it now is all wrong. Read the helpfile to see how you should do it. Also, check out IsArray to see if it is or not.

Maybe have a closer look at your code and make sure you're doing things correctly... Check out the returns and how you are using them. Cause right now there are a lot of simple errors resulting from how you're doing it.

Cheers,

Brett

Share this post


Link to post
Share on other sites

i've beeu using the debug console the builtin one> seems like all the handles for the files are returning invalid even though it clearly loads the file.

AutoIt:3.3.6.0/X64   (Os:WIN_7/X64   Language:0409 Keyboard:00000409 Cpu:X64)

C:\Users\RO\Pictures\Untitled12.jpg : The handle is invalid.

What do you make of it?

Share this post


Link to post
Share on other sites

Sorry. Also i looked through the examples and tried to see what i was doing wrong and even these applications that have been tested and passed tests sday the file handle isn't valid yet they still do what they are suppose to

Share this post


Link to post
Share on other sites

Like I said previously. You're doing it wrong. I no way have you attempted to see the root of the problem, starting with line 1...

I've attempted to try and work out what you are trying to do without much luck so I hope this is what you're after. If not, explain exactly what you needed.

#include <ComboConstants.au3>

#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <TreeViewConstants.au3>
#include <WindowsConstants.au3>
#include <Constants.au3>
#include <GuiComboBox.au3>
#include <WinAPI.au3>
#include <GuiTreeView.au3>
#include <Debug.au3>


Global $DefaultFileName = "Untitled"
Global $File = 1
Global $ArraySize = 10000000
Dim $FileFormat
Global $ComboBox2
Global $CurSel, $hImage, $iImage

; These is the include files we need for this script to do what we want.
#region ### START Koda GUI section ### Form=c:\users\ro\documents\autoitscripts\encryption\archive.kxf
$Archive = GUICreate("Archive Format v1.0", 579, 386, 198, 144)
GUISetIcon("C:\Program Files\WinRAR\WinRAR.exe", -1)
$Group1 = GUICtrlCreateGroup("Custom Archive Format", 8, 8, 561, 369)
$Pic1 = GUICtrlCreatePic("C:\Users\RO\Documents\AutoITscripts\Encryption\Images\Marcus.gif", 16, 32, 293, 241)
$Button1 = GUICtrlCreateButton("Add Files to Archive (.arch)", 360, 296, 161, 25)
$Browse = GUICtrlCreateButton("....", 528, 296, 33, 25)
$TreeParent = _GUICtrlTreeView_Create($Archive, 344, 32, 209, 241, BitOR($GUI_SS_DEFAULT_TREEVIEW, $TVS_EDITLABELS, $TVS_NOTOOLTIPS, $TVS_CHECKBOXES, $TVS_TRACKSELECT, $TVS_INFOTIP, $TVS_FULLROWSELECT, $TVS_NONEVENHEIGHT, $WS_BORDER))
GUICtrlCreateGroup("", -99, -99, 1, 1)

GUISetState(@SW_SHOW)

While 1
    $nMsg = GUIGetMsg()
    Select
        Case $nMsg = $GUI_EVENT_CLOSE
            Exit
        Case $nMsg = $Browse
            ;FileOpenDialog does not return an array only a string
            $FileFormat = FileOpenDialog("Browse for files to encode", @WorkingDir, "Any File (*.*)", 4)
            ;So we split it here
            $FileFormat = StringSplit($FileFormat, "|", 2)
            ;Begin updating
            _GUICtrlTreeView_BeginUpdate($TreeParent)
            ;Add the directory as the parent
            ;Also not sure why you had  StringFormat("[%02d] New Item", ...) here either?  Read the helpfile to see why.  You do know it exists right?
            $hItem = _GUICtrlTreeView_Add($TreeParent, 0, $FileFormat[0]) ;$iImage, $iImage)
            ;Loop through each of the files
            For $i = 1 To UBound($FileFormat) - 1
                ;Add the child elements (the files)
                _GUICtrlTreeView_AddChild($TreeParent, $hItem, $FileFormat[$i]); $iImage, $iImage)
            Next
            ;End update
            _GUICtrlTreeView_EndUpdate($TreeParent)
    EndSelect
WEnd

Cheers,

Brett

Share this post


Link to post
Share on other sites

YES!!! that is exactly what i was after! thanks. i've been trying to do that my self. also, is there a way to click on the TrayTip icon when it's visible>? you know lkie sometimes the tip shows up and only disappears when u click on it, opening a dialog? Thanks again, Sorry that i couldn't explain my self better...

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  
Followers 0