david1337 Posted October 19, 2015 Share Posted October 19, 2015 (edited) Hi guysI have a folder --> "C:\Test\" containing different txt files named: test1.txt, test2.txt, test3.txt etc.Each txt file contains lists of names seperated by line breaks like:Content of test1.txt;JackMarcusMichaeletc etc...Is it possible to show the content of all txt files in 1 list/view, separated with rows that are named after the name of the txt file:test1 | test2 | test 3 | ________|_________|__________| Jack | Kim | Jennifer | Marcus | Britney | John | Michael | Tom | Brad | I haven't come closer in a script than to show the content of a single file in an msgbox, and that is without the row headline, "test1" :-( $File1 = "C:\Test\test1.txt" MsgBox(0, "Content of File", FileRead($File1)) Edited October 19, 2015 by david1337 Link to comment Share on other sites More sharing options...
MagnumXL Posted October 19, 2015 Share Posted October 19, 2015 You are going to want to use _FileListToArray to add each file and then just step through the arrays formatting them for your listview. Link to comment Share on other sites More sharing options...
Danyfirex Posted October 19, 2015 Share Posted October 19, 2015 (edited) You can do something like this:expandcollapse popup#include <GUIConstantsEx.au3> #include <GuiImageList.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Global $g_hListView Example() Func Example() Local $hGUI, $hImage $hGUI = GUICreate("Litview", 400, 300) Local $sDirPath = "C:\test" $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, BitOR($LVS_EX_GRIDLINES, $LVS_EX_FULLROWSELECT, $LVS_EX_SUBITEMIMAGES)) GUISetState(@SW_SHOW) Local $aFiles = _FileListToArray($sDirPath) ;~ _ArrayDisplay($aFiles) Local $aString = 0 For $i = 1 To $aFiles[0] _GUICtrlListView_InsertColumn($g_hListView, 0, $aFiles[Abs(($aFiles[0] * -1) + $i) + 1], 100) $aString = FileReadToArray($sDirPath & "\" & $aFiles[$i]) If $i = 1 Then For $x = 0 To UBound($aString) - 1 _GUICtrlListView_AddItem($g_hListView, $aString[$x]) Next Else For $x = 0 To UBound($aString) - 1 _GUICtrlListView_AddSubItem($g_hListView, $x, $aString[$x], $i - 1) Next EndIf Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>ExampleSaludos Edited October 19, 2015 by Danyfirex Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
mikell Posted October 19, 2015 Share Posted October 19, 2015 It could be a little tricky if the text files contain a different number of namesexpandcollapse popup#include <GUIConstantsEx.au3> #include <GuiListView.au3> #include <WindowsConstants.au3> #include <Array.au3> #include <File.au3> Global $g_hListView Example() Func Example() Local $hGUI, $hImage $hGUI = GUICreate("Litview", 400, 300) Local $sDirPath = @scriptdir $g_hListView = _GUICtrlListView_Create($hGUI, "", 2, 2, 394, 268) _GUICtrlListView_SetExtendedListViewStyle($g_hListView, $LVS_EX_GRIDLINES) GUISetState(@SW_SHOW) Local $aFiles = _FileListToArray($sDirPath, "*.txt") ;~ _ArrayDisplay($aFiles) Local $n For $i = 1 To $aFiles[0] $tmp = _FileCountLines($sDirPath & "\" & $aFiles[$i]) $n = ($n<$tmp) ? $tmp : $n Next For $i = 0 To $n _GUICtrlListView_AddItem($g_hListView, "") Next Local $aString = 0 For $i = 1 To $aFiles[0] _GUICtrlListView_AddColumn($g_hListView, $aFiles[$i], 100) $aString = FileReadToArray($sDirPath & "\" & $aFiles[$i]) If $i = 1 Then For $x = 0 To UBound($aString) - 1 _GUICtrlListView_SetItemText($g_hListView, $x, $aString[$x]) Next Else For $x = 0 To UBound($aString) - 1 _GUICtrlListView_AddSubItem($g_hListView, $x, $aString[$x], $i - 1) Next EndIf Next ; Loop until the user exits. Do Until GUIGetMsg() = $GUI_EVENT_CLOSE GUIDelete() EndFunc ;==>Example Link to comment Share on other sites More sharing options...
Danyfirex Posted October 19, 2015 Share Posted October 19, 2015 @mikell you have broken my script's copyright lol. Good ternary trick. Saludos Danysys.com AutoIt... UDFs: VirusTotal API 2.0 UDF - libZPlay UDF - Apps: Guitar Tab Tester - VirusTotal Hash Checker Examples: Text-to-Speech ISpVoice Interface - Get installed applications - Enable/Disable Network connection PrintHookProc - WINTRUST - Mute Microphone Level - Get Connected NetWorks - Create NetWork Connection ShortCut Link to comment Share on other sites More sharing options...
david1337 Posted October 19, 2015 Author Share Posted October 19, 2015 Holy shit guys, that's awesome!Exactly what I wanted to achieve! Thank you very much._GUICtrlListView_AddColumn($g_hListView, $aFiles[$i], 100)I see that this is the line that defines the names of the rows. Is it possible to hide the ".txt" part? Saludos Link to comment Share on other sites More sharing options...
ViciousXUSMC Posted October 19, 2015 Share Posted October 19, 2015 _GUICtrlListView_AddColumn($g_hListView, StringTrimRight($aFiles[$i], 4), 100) Link to comment Share on other sites More sharing options...
david1337 Posted October 19, 2015 Author Share Posted October 19, 2015 _GUICtrlListView_AddColumn($g_hListView, StringTrimRight($aFiles[$i], 4), 100) Thanks! That's perfect. Didn't know about StringTrim. Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now