Jump to content

Stupid Question list of files


Recommended Posts

I know I've seen this in the past, its just one of those things that when you think you dont need it you pay it no mind then when you need it its gone.

Well what I would like is to have a list of files in a specific folder, that when I click on one or more of them it performs certain actions to them. What I want it to do is look in a certain folder for all ini files and bring up the list so I can pick which one to view first. I'd post what I have but so far I'm stumped.

Giggity

Link to comment
Share on other sites

I just posted about this earlier today.

_FileListToArray

And loop through the array and add a treeviewitem for each file. Use the treeview UDFs, they are much better than the built in ones

Regards,Josh

Link to comment
Share on other sites

I know I've seen this in the past, its just one of those things that when you think you dont need it you pay it no mind then when you need it its gone.

Well what I would like is to have a list of files in a specific folder, that when I click on one or more of them it performs certain actions to them. What I want it to do is look in a certain folder for all ini files and bring up the list so I can pick which one to view first. I'd post what I have but so far I'm stumped.

You can use FileFindFirstFile to create your list of files, and GUICtrlCreateList to view it. Does that help?

Link to comment
Share on other sites

@JFee,

I believe I saw that earlier, but I don't know anything about UDF's and I'm just starting on working on understanding Array's. I was hoping it would be simpliar then learning alot of new stuff, kind of like RodT's

@RodT

I looked at the FileFindFirstFile in the help but it didn't look like what I was looking for but now I look at it again and I think that may work. I'm sure I'll get stuck again shortly, and will post where I've gotten so far.

Giggity

Link to comment
Share on other sites

Arrays are very simple, and a very valuable resource to know how to use. Basically think of an Excel spreadsheet as 2 dimensional array. Lets say you have 10 rows and 10 columns, $array[5][4] gives you the value from the cell in the 5th row and 4th column.

the _FileListToArray function doesn't even have that... it is a 1 dimensional array meaning:

$array[1] will contain the first file it found, $array[2] the second, etc. $array[0] tells you how many files you found, so you do something like this:

$fileArray = _FileListToArray("directory")

For $i = 1 to $fileArray[0]  ;For each of the files it found:
   ;Create a Treeview item with text $fileArray[$i]
Next

Regards,Josh

Link to comment
Share on other sites

@JFee

Thanks for the explaination, I have an understanding of how they work, just not how to use them completely. I tried to combine it all into one but this is what I got, and it doesn't work... I had it so it was creating the list, but it had 0 instead of the filenames in the folder. then when I tried the array, I broke it. So here's what I got, The List should appear when you click search, all the way at the bottom of the script.

#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <GDIPlus.au3>
#Include <WinAPI.au3>
#Include <File.au3>
#Include <Array.au3>
Global $files
$power = GUICreate("What would you like to do?", 500, 500) 

GUICtrlCreateLabel("Base Layer Configuration", 10, 10)
$neworedit = GUICtrlCreateCombo("", 10, 50)
GUICtrlSetData(-1, "New|Edit", "Edit") 
GUICtrlCreateLabel("Which Database?", 10, 90)
$database = GUICtrlCreateCombo("", 10, 130)
GUICtrlSetData(-1, "Package|Import|Mold", "Package") 

$goBUTTON = GUICtrlCreateButton("Go", 150, 450, 60)
$searchbutton = GUICtrlCreateButton("search", 250, 450, 60)
GUISetState(@SW_SHOW)

While 1
  $msg = GUIGetMsg()
  Select
    Case $msg = $gobutton
      If GUICtrlRead($neworedit) = "New" and GUICtrlRead($database) = "import" Then
      MsgBox(0, "include", "replace with include to new imports")
      ElseIf GUICtrlRead($neworedit) = "New" and GUICtrlRead($database) = "package" Then
      MsgBox(0, "include", "replace with include to new package")
  Else
      If GUICtrlRead($neworedit) = "New" and GUICtrlRead($database) = "mold" Then
      MsgBox(0, "include", "replace with include to new mold")
      ElseIf GUICtrlRead($neworedit) = "edit" and GUICtrlRead($database) = "import" Then
      MsgBox(0, "include", "replace with include to edit import")
  Else
      if GUICtrlRead($neworedit) = "edit" and GUICtrlRead($database) = "package" Then
      MsgBox(0, "include", "replace with include to edit package")
      ElseIf  GUICtrlRead($neworedit) = "edit" and GUICtrlRead($database) = "mold" Then
      MsgBox(0, "include", "replace with include to edit mold")
  Else
      MsgBox(0, "incorrect", "incorrect input")
  EndIf
  EndIf
  EndIf
      
      
      Exit
        Case $msg = $GUI_EVENT_CLOSE
          #include <Exitgui.au3>
      Case $msg = $searchbutton
          
           $fileArray = _FileListToArray("C:\AutoIt v3 Script\final")

For $i = 1 to $fileArray[0] ;For each of the files it found:
  ;Create a Treeview item with text $fileArray[$i]
Next


          $files = FileFindFirstFile("C:\AutoIt v3 Script\final\*.*")
          GUICtrlCreateList ($fileArray($1), 10, 200, 100, 200)
          GUICtrlSetLimit(-1, 200)  
          
         
    
    
        
    

    
  EndSelect
WEnd

Giggity

Link to comment
Share on other sites

That is an awfully funny looking If Then Else.... lookup ElseIf instead of making 3 nested If statements.

As for the search button... you should get rid of

$files = FileFindFirstFile("C:\AutoIt v3 Script\final\*.*")
          GUICtrlCreateList ($fileArray($1), 10, 200, 100, 200)
          GUICtrlSetLimit(-1, 200)

You don't need that. $fileArray is a variable that contains all of the files, so the ForNext loop goes through each file it found and should add an item to a treeview, or since you seem to want to use a list, a list.

If you read the script I posted... you would've noticed that I didn't do all of the work for you. Right the ForNext loop does nothing because there is one line inside it, and it is a comment.

Inside there you need to put the guictrlcreate or guictrlsetdata for the treeview or list. Use the help file to learn what a For Next loop does, because it seems like you are a little lost.

Give this a shot then post back with your code if you are still having problems.

Regards,Josh

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...