Listbox Folder Contents

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Listbox Folder Contents

27 Sep 2021, 22:24

I need to get a list of txt files in a folder that is set as default as in code but can browse to new folder.
I don't want the path name to show.
Selecting the item in listbox will display the text contained in the file in the box below.
Save will save any edits in the text box to the same filename file.
Entering a new filename will save as new file with whatever text is in text box.
The Ok will be a function like copy the text contained to clipboard then send to an app with paste.
If it had an ini to remember last folder would be good if not too much of a problem.
Any help would be much appreciated.
AHK-Listbox-Folder.png
AHK-Listbox-Folder.png (57.22 KiB) Viewed 749 times

Something like this code but with text edit box below:
https://autohotkey.com/board/topic/6766-loading-listbox-with-file-names/

Code: Select all

;To cancel, press ESCAPE or close this window. 
Gui, Add, ListBox, vListBox_pdf x16 y10 w370 h125,
Gui, Add, ListBox, vListBox_ini x16 y145 w370 h125,
Gui, Add, Button, Default, OK

;----------------------------- Start Fill Listboxs
Loop, C:\temp\*.pdf
{ 
   GuiControl,, ListBox_pdf, %A_LoopFileFullPath% 
} 
Loop, C:\*.ini
{ 
   GuiControl,, ListBox_ini, %A_LoopFileFullPath% 
} 
Gui, Show 
return 
;----------------------------- End Fill Listboxs

;------------------------------Start OK Button
ButtonOK: 
GuiControlGet, ListBox_pdf  		; Retrieve pdf selection. 
GuiControlGet, ListBox_ini  		; Retrieve ini selection.
MsgBox, 4,, Open Current Selections:`n`n%ListBox_pdf% & `n%ListBox_ini%
IfMsgBox, No 
   return 
; ---(Example of how to handle the logic in a Yes/No Msgbox)
;	Run, %ListBox_pdf%,, UseErrorLevel 
;	Run, %ListBox_ini%,, UseErrorLevel 
;	if ErrorLevel = ERROR 
;	   MsgBox Could not launch the specified file.
;	return
;----------------------------- End OK Button
GuiClose: 
GuiEscape: 
ExitApp
Last edited by MusoCity on 29 Sep 2021, 01:29, edited 1 time in total.
User avatar
mikeyww
Posts: 26848
Joined: 09 Sep 2014, 18:38

Re: Listbox Folder Contents

28 Sep 2021, 05:26

You could use an edit control. You would have a g-label in your listbox. It would call a subroutine that does FileRead and then GuiControl to show the text. Your save can then FileAppend.

Are you facing a barrier or question, or just want someone to write the program?
MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Listbox Folder Contents

28 Sep 2021, 10:44

I would appreciate if someone could modify the code to give the results, thanks.
Ahk_fan
Posts: 237
Joined: 31 Aug 2018, 14:34
Contact:

Re: Listbox Folder Contents

30 Sep 2021, 15:41

Code: Select all

;To cancel, press ESCAPE or close this window. 
Gui, New
Gui, Margin	, 5, 5
Gui, Add		, Button	, Section Default										, Reload
Gui, Font		, s10		, Arial
Gui, Add		, Edit		, xs w320 vMyFolder							, C:\temp\1
Gui, Font		, s8		, Wingdings
Gui, Add		, Button	, x+10 w35 gGetNewFolder								, 1
Gui, Font		, s10 		, Arial
Gui, Add		, ListView	, xs vListBox_pdf w370 h125	gClickPdf AltSubmit	,File|Path
Gui, Add		, ListView	, xs vListBox_ini w370 h125	gClickIni AltSubmit	,File|Path
Gui, Add		, ActiveX	, xs w300 h600 vWB VScroll	, IE.Browser
ComObjConnect(WB, WB_events)  ; Connect WB's events to the WB_events class object.
GuiControl, Hide, WB
Gui, Add		, Edit		, x+20 Section w200 h600 vEditor							, 
GuiControl, Hide, Editor
Gui, Font		, s8		, Wingdings
Gui, Add		, Button	, xs gSaveIni vButtonSave								, <
Gui, Add		, Button	, x+10 gSaveAsIni vButtonSaveAs 						, <!
Gui, Font		, s10 		, Arial
Gui, Add		, Button	, x+10 gSaveClipb vButtonClipboard						, Clipboard
GuiControl, Hide, ButtonSave
GuiControl, Hide, ButtonSaveAs
GuiControl, Hide, ButtonClipboard
gosub, FillListView
Gui, Show , w650 , test
return 

ButtonReload:
	Reload
Return

GuiClose: 
GuiEscape: 
ExitApp

SaveIni:
	Gui, Submit, NoHide
	FileDelete, %RowTextclickedinipath%\%RowTextclickedinifile% 
	While FileExist(RowTextclickedinipath "\" RowTextclickedinifile)
	{
		Sleep, 200
		if A_Index > 20
		{
			MsgBox, 16, Error, File ist open, please close File and repeat!
			Return
		}
	}
	FileAppend, %Editor%, %RowTextclickedinipath%\%RowTextclickedinifile% 
return

SaveAsIni:
	Gui, Submit, NoHide
	InputBox, OutputVarFileNameNew , Filename, Enter new Filename, , , , , , , , .ini
	if ErrorLevel
		MsgBox, CANCEL was pressed.
	else
	{
		FileAppend, %Editor%, %MyFolder%\%OutputVarFileNameNew%
		gosub, FillListView
	}
return

SaveClipb:
	Clipboard := Editor
Return

FillListView:
	Gui, Submit, NoHide
	;----------------------------- Start Fill ListViews
	Gui, ListView, ListBox_pdf
	LV_Delete()
	Loop, %MyFolder%\*.pdf
	{ 
		row := LV_Add("", A_LoopFileName, A_LoopFileDir)
		;GuiControl,, ListBox_pdf, %A_LoopFileName%      ;%A_LoopFileFullPath% 
	}
	LV_ModifyCol()
	Gui, ListView, ListBox_ini
	LV_Delete()
	Loop, %MyFolder%\*.ini
	{ 
		row := LV_Add("", A_LoopFileName, A_LoopFileDir)	
		;GuiControl,, ListBox_ini, %A_LoopFileName% 
	} 
	LV_ModifyCol()
Return

GetNewFolder:
	Gui, submit, nohide
	FileSelectFolder, OutputVar , c:\, 3, Select Folder
	if OutputVar =
		MsgBox, You didn't select a folder.
	else
	{
		GuiControl, , MyFolder, %OutputVar%
		gosub, FillListView
	}
Return

ClickPdf:
	Gui, submit, nohide
	if A_GuiEvent = Normal
	{
		;MsgBox, 1
		GuiControl, Hide, Editor
		GuiControl, Hide, ButtonSave
		GuiControl, Hide, ButtonSaveAs
		GuiControl, Hide, ButtonClipboard
		GuiControl, Show, WB
		Gui, ListView, ListBox_pdf
		LV_GetText(RowTextclickedpdffile, A_EventInfo, 1)
		LV_GetText(RowTextclickedpdfpath, A_EventInfo, 2)
		GuiControl, , Editor, 
		WB.Navigate( RowTextclickedpdfpath "\" RowTextclickedpdffile)
	}
return

ClickIni:
	Gui, submit, nohide
	if A_GuiEvent = Normal
	{
		;MsgBox, 2
		GuiControl, Hide, WB
		
		GuiControl, Show, Editor
		GuiControl, Show, ButtonSave
		GuiControl, Show, ButtonSaveAs
		GuiControl, Show, ButtonClipboard
		Gui, ListView, ListBox_ini
		LV_GetText(RowTextclickedinifile, A_EventInfo, 1)
		LV_GetText(RowTextclickedinipath, A_EventInfo, 2)
		FileRead, TextOutput, %RowTextclickedinipath%\%RowTextclickedinifile%
		WB.Navigate("")
		GuiControl, , Editor, %TextOutput%
	}
return
regards,
AHK_fan :)
https://hr-anwendungen.de
MusoCity
Posts: 95
Joined: 24 Mar 2018, 20:45

Re: Listbox Folder Contents

30 Sep 2021, 20:33

Thanks !! I got it working basically but this will help a lot to add the browse and ini.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Google [Bot], mamo691, mcd, mikeyww, MrDoge, ReyAHK and 238 guests