PINTO1927

GUICtrlCreateListViewItem all file *.txt

12 posts in this topic

 

Hello guys, I would have the need to import into the GUICtrlCreateListView all * .txt files in a folder. The * .txt files contain all of the same formatting separated by "|", the script should go on every single file and bring me back the result in the GUICtrlCreateListView. For now I only managed to upload a single file * .txt into the GUICtrlCreateListView with this code:

Case $Button_Find
   $File_txt = "\\cond\UPDATE\test.txt"
   Dim $Array_List
   _FileReadToArray($File_txt, $Array_List)
   $Limit_Array = UBound($Array_List) - 1
   For $i = 1 To $Limit_Array
      $All_Box = String($Array_List[$i])
      GUICtrlCreateListViewItem($All_Box, $List)
   Next
   For $i2 = 0 To _GUICtrlListView_GetColumnCount($List)
   _GUICtrlListView_SetColumnWidth($List, $i2, $LVSCW_AUTOSIZE_USEHEADER)
   Next

:sweating:

Share this post


Link to post
Share on other sites



PINTO1927,

Quote

all * .txt files in a folder

So use _FileListToArray to get the list of files and then loop through the array to read each of them in turn using your existing _FileReadToArray code to extract the data..

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

For now I can only get the name of each .txt file. To get the contents of each file and place it in GUICtrlCreateListView I tried using FileOpen and FileRead but I can not get the result I want.

Can you show me an example? Thank's

Share this post


Link to post
Share on other sites

PINTO1927,

Try using _FileReadToArray to get the content of each file - then you can loop through that array and add each one in turn. Just be careful to use a different loop variable in the nested loops.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

 

i'm becoming crazy.. :mad:

Share this post


Link to post
Share on other sites

PINTO1927,

So what code have you tried using _FileReadToArray that has not worked?

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

 

I'm trying to study _FileListToArray("\\cond\UPDATE\", "*.txt", 0 ) to add in code.

 

I can not get results..

Do you have a silly example to show me?:sweating:

 

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

PINTO1927,

Take a look at this:

#include <File.au3>

; Read the intial files into an array
Local $aFiles = _FileListToArray(@ScriptDir, "Test*.txt", $FLTA_FILES, True)

; Now loop through these files
Local $aLines
For $i = 1 To $aFiles[0]
    ; And read their content into an array
    _FileReadtoArray($aFiles[$i], $aLines)
    ; Now loop through the content
    For $j = 1 To $aLines[0]
        ; And extract each line in turn
        ConsoleWrite($aLines[$j] & @CRLF)
    Next
Next

I used these files: for testing.

M23

Edited by Melba23

Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

PINTO1927,

Glad I could help.

M23


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

 

Sorry Melba, last comment.

if you wanted to add a _GUICtrlListView_GetItemChecked for each string added in the GUICtrlCreateListView?

Share this post


Link to post
Share on other sites
$LVS_EX_CHECKBOXES

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

  • Similar Content

    • FrancescoDiMuro
      By FrancescoDiMuro
      Good evening everyone
      I'm working on this little project for a week, and, what I'm trying to do could be useful for many users as well...
      I'm trying to do a "Report Generator", which reads the data that have to report from a text file (.txt) formatted with this pattern;
      Data1;Data2;Data3;Data4;Data5;;

      YES, there are 2 semi-colon at the end of the line.

      In detail, Data1 is a date/time stamp with this format: YYYY/MM/DD HH:MM:SS ;

      When the script starts, the user is prompted to choose 2 dates which I'll call as:
      Report_Date_Start; Report_Date_Start. So, the report, should cover all dates between Report_Date_Start AND Report_Date_End.

      And, already at this point, I don't know how to do the query... How can I say to the script:
      SELECT * FROM (.txt) WHERE Data1 BETWEEN Report_Date_Start AND Report_Date_End; ?

      I thought that I could do a _DateDiff, but if the difference between the two dates is months and not days, how can I do the trick?
      Should I make a Switch...Case with the _DateDiff() and see then calculate all the dates between Report_Date_Start AND Report_Date_End... But then, how can I compare the dates in the file with all the dates between Report_Date_Start AND Report_Date_End? I'm going crazy, I know...

      I've already made a "Export Tool", which exports the content of the .txt file in a .db, managed with SQLite... I mean, there I could easily do a query like I did above the thread, but, this "export", for 1080 rows, takes 28 seconds to be done. And, 1080 rows are daily rows that are added every day in the .txt file, so, in a week, the file could be easily 7000+ rows, which means that the "export" would take 3 minutes to be done... And we can go over and over...
      I'll post just for be "complete" what I've done about the export, so, maybe, someone could say how to improve it in terms of efficency...
       
      Local $aContenutoFileAuditReport = "" _FileReadToArray($sFileAudit_Report, $aContenutoFileAuditReport) If(IsArray($aContenutoFileAuditReport) And Not @error) Then Local $aContenutoFileAuditReport_Splitted = "" Local $sQuery = "" Local $hInizioConteggio = TimerInit() For $i = 1 To UBound($aContenutoFileAuditReport) - 1 $aContenutoFileAuditReport_Splitted = StringSplit($aContenutoFileAuditReport[$i], ";") $sQuery = "INSERT INTO FileDB_Report(DATESTAMP, TIMESTAMP, USER_ID, OBJECT_ID, DESCRIPTION, COMMENT) " & _ "VALUES(" & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[0]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[1]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[3]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[4]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[5]) & "," & _ _SQLite_FastEscape($aContenutoFileAuditReport_Splitted[6]) & ");" If(_SQLite_Exec($hFileDB_Report, $sQuery) <> $SQLITE_OK) Then ConsoleWrite("Errore durante l'esecuzione della query #" & $i & @CRLF) Else ConsoleWrite("Query eseguita correttamente #" & $i & @CRLF) EndIf Next ConsoleWrite("Esportazione completata in: " & Round(TimerDiff($hInizioConteggio)/1000, 0) & " secondi") Else MsgBox($MB_ICONERROR, "Errore!", "Errore durante la lettura del file nell'array." & @CRLF & "Errore: " & @error) EndIf I know that I can't do queries from a .txt file...
      [19:18] 
      I've been writing this post from 18:40 maybe...
      By the way, if @jchd or someone else could tell me if I can import a formatted .txt file in SQLite and then, do queries on the DB, I'd be very happy for that...
      About the report in PDF, I'm talking with @taietel in order to know how to create a PDF.
      I hope someone will help me
      Sorry for the "long" list of questions...
      Thank you for everything you've done for me
      I have to say that this is the community of programming language that I've loved most!
      By the way, I'll be back tomorrow in the morning ( ~ 9:15 a.m. Italian time ), so, excuse me if I can't answer before that time.
      Hope you guys have a wonderful day/night.

      Thanks again

      Francesco
    • 6401integramandj
      By 6401integramandj
      I am very new to Autoit and pretty new to scripting altogether.I have a PowerShell script that pulls owner info from folders on our file share server. There are 3 owners for every folder, Domain Admin, User setup for network scanning and the user. I am trying to copy the username only from this txt file. I have gotten as far as to being able to read the lines in the txt file but can't seem to read the columns. This is what i have so far.
      #include <File.au3>
      $file = "c:\test01.txt"
      FileOpen($file, 0)
      For $i = 5 to _FileCountLines($file)
          $line = FileReadLine($file, $i)

       msgbox(0,'','the line ' & $i & ' is ' & $line & 'and the column is')
      Next
      FileClose($file)
       
      This is the outcome.....

      This is the txt file

      I am trying to copy the ABC part without the MyDomain\. I know it's line 5 and columns 11-14 of the txt file but i can't figure out how to read it. I hope i'm explaining this correctly. 
    • PINTO1927
      By PINTO1927
      Hi Guys,
      I'm working on this project:
      $Import = GUICtrlCreateButton("Import", 15, 175, 90, 40, $WS_GROUP) $List = GUICtrlCreateListView("Name|Address|E-mail", 15, 220, 400, 363, $LVS_SORTDESCENDING) $Item1 = GUICtrlCreateListViewItem("test|test|test", $List) GUISetState(@SW_SHOW, $GUI) While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE, $Exit Exit Case $Import $Table_Import = FileOpenDialog("Import list '*.txt'", @DesktopDir & "\", "Text (*.txt)") If @error Then ContinueLoop GUICtrlSetData($Item1, $Table_Import) In the text file the fields are delimited with "|" and the values are not in the same row but one below the other.
      However in the txt file the sum of the values may change.
      Can you help me?
      Thank's
    • PINTO1927
      By PINTO1927
      Hello guys,
      I built a gui where a GUICtrlCreateListView with two columns is present.
      Through an "Import" button I would be able to import the contents of an .xls or .txt.
      Can you help me?
      Thank's