Jump to content

Generate list to txt


Recommended Posts

Hi

I searched on the forum but have been unable to find a way to generate a .txt file that has the name of all files in a folder line by line , example :

file1.ini

file2.ini

file3.ini

My code needs to load info from files in a specific folder but to do that i need a generate list so i have arguments to load them..something around the lines of :

$file = FileOpen("generatedlist.txt", 0)
$line = FileReadLine($file[1])
$var = IniRead($line, "NAME", "key", "")
GUICtrlSetData($var, $showname) 
$line2 = FileReadLine($file[2])
$var2 = IniRead($line2, "NAME", "key", "")
GUICtrlSetData($var2, $showname2)

and so on and so forth..so that the 40 input boxes have the the Names inside each .ini file loaded in the boxes..

any help would be appreciated

thx

P.S i think there was a dos command script that generated lists but i havent been able to find it with the forum search option.

Edited by melf
Link to comment
Share on other sites

  • Moderators

Look at FileFindFirstFile()/FileFindNextFile() - Then Store them in an array or write them to the file you want, and sort as needed.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

hmmm

and how could i set it so that each FileFindNextFile find has an automatic numbered $var? ( $var1, $var2$, etc) without having to script an entry for each?

Edited by melf
Link to comment
Share on other sites

  • Moderators

If that's the case then just look at the Beta _FileListToArray() option, nice and simple return.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

hmm k let me rephrase that

i want to know how to set the FileFindNextFile find to a seperate attribute

( first file name found name becomes $var1 , second name become's $var2 , etc..)

im having trouble's understanding the arrays

Link to comment
Share on other sites

  • Moderators

hmm k let me rephrase that

i want to know how to set the FileFindNextFile find to a seperate attribute

( first file name found name becomes $var1 , second name become's $var2 , etc..)

im having trouble's understanding the arrays

The function I gave you (_FileListToArray()) will do that. Just give it the File/Folder you want to search.

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

Ah ok..i get it now..but lets say i want it to skip an empty array?

i got 10 entry's but lets say i have only 6 files in the folder?..for the moment the script crashes on me because i have excedding arrays..

#Include <File.au3>
#Include <Array.au3>
#include <GuiConstants.au3>

GuiCreate("MyGUI", 800, 600,-1, -1 )
GUICtrlCreateLabel("Number", 10, 32) 
$nombres = GUICtrlCreateInput("", 96, 32, 30, 20) 
$autobus = GUICtrlCreateInput("", 96, 52, 130, 20) 
$autobus1 = GUICtrlCreateInput("", 96, 72, 130, 20) 
$autobus2 = GUICtrlCreateInput("", 96, 92, 130, 20) 
$autobus3 = GUICtrlCreateInput("", 96, 112, 130, 20) 
$autobus4 = GUICtrlCreateInput("", 96, 132, 130, 20)
$autobus5 = GUICtrlCreateInput("", 96, 152, 130, 20) 
$autobus6 = GUICtrlCreateInput("", 96, 172, 130, 20) 
$autobus7 = GUICtrlCreateInput("", 96, 192, 130, 20) 
$autobus8 = GUICtrlCreateInput("", 96, 212, 130, 20) 
$autobus9 = GUICtrlCreateInput("", 96, 232, 130, 20) 
$FileList=_FileListToArray("C:\Database\Autobus\")
    GUICtrlSetData($nombres, $FileList[0]) 
    GUICtrlSetData($autobus, $FileList[1]) 
    GUICtrlSetData($autobus1, $FileList[2])
           GUICtrlSetData($autobus2, $FileList[3])      
           GUICtrlSetData($autobus3, $FileList[4])  
           GUICtrlSetData($autobus4, $FileList[5])
           GUICtrlSetData($autobus5, $FileList[6])         
           GUICtrlSetData($autobus6, $FileList[7])  
           GUICtrlSetData($autobus7, $FileList[8])  
           GUICtrlSetData($autobus8, $FileList[9])  
           GUICtrlSetData($autobus9, $FileList[10])                

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd
Exit
Link to comment
Share on other sites

  • Moderators

See if this works for you:

#Include <File.au3>
#include <GuiConstants.au3>

Global $autobus[11]
Global $FileList=_FileListToArray("C:\Database\Autobus\")
$main = GuiCreate("MyGUI", 800, 600,-1, -1 )
$label1 = GUICtrlCreateLabel("Number", 10, 32)
$nombres = GUICtrlCreateInput("", 96, 32, 30, 20)
For $i = 1 To UBound($FileList) - 1
    If $i > 10 Then ExitLoop ; If the file has more than 10 files, it will only list the first 10
    $autobus[$i] = GUICtrlCreateInput("", 96, 32 + ($i * 20), 130, 20)
    GUICtrlSetData($autobus[$i], $FileList[$i])
Next
GUICtrlSetData($nombres, $FileList[0])

GuiSetState()
While 1
    $msg = GuiGetMsg()
    Select
    Case $msg = $GUI_EVENT_CLOSE
        ExitLoop
    Case Else
    ;;;
    EndSelect
WEnd

P.S., Thanks for using code tags :D

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

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