Edit ListBox to show file name only?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
bballjoe12
Posts: 114
Joined: 20 Aug 2017, 09:11

Edit ListBox to show file name only?

19 Oct 2017, 07:08

I was wondering how to have the ListBox just show the file name rather then the whole file path. I looked through the AHK Guide Loops but couldn't find what I was looking for.

Code: Select all

OnExit, CloseS
DetectHiddenWindows On
SetWorkingDir %A_ScriptDir%

Menu FileMenu, Add, Exit, MenuHandler
Menu MenuBar, Add, File, :FileMenu
Menu Tray, Icon, skull.ico
Gui Menu, MenuBar

WinGet, WList,List,ahk_class AutoHotkey
Loop %WList%
{
Id:=% "WList" A_Index
WinGetTitle, Title, % "ahk_id " %Id%
a.=Title "|"
}

Gui, Add, ListBox, w400 h100 gClicked vpicked , %a%
Gui, Show, w430 h102, Running Scripts
Return

Clicked:
Gui, Submit
WinClose, %Picked% 	;to close script
Return

CloseS:
ExitApp

MenuHandler:
ExitApp

ExitApp
User avatar
TheDewd
Posts: 1513
Joined: 19 Dec 2013, 11:16
Location: USA

Re: Edit ListBox to show file name only?

19 Oct 2017, 07:39

Use SplitPath

Code: Select all

OnExit, CloseS
DetectHiddenWindows On
SetWorkingDir %A_ScriptDir%

Menu FileMenu, Add, Exit, MenuHandler
Menu MenuBar, Add, File, :FileMenu
Menu Tray, Icon, skull.ico
Gui Menu, MenuBar

WinGet, WList,List,ahk_class AutoHotkey
Loop %WList%
{
Id:=% "WList" A_Index
WinGetTitle, Title, % "ahk_id " %Id%
SplitPath, Title, TitleFileName
a.=TitleFileName "|"
}

Gui, Add, ListBox, w400 h100 gClicked vpicked , %a%
Gui, Show, w430 h102, Running Scripts
Return

Clicked:
Gui, Submit
WinClose, %Picked% 	;to close script
Return

CloseS:
ExitApp

MenuHandler:
ExitApp

ExitApp
bballjoe12
Posts: 114
Joined: 20 Aug 2017, 09:11

Re: Edit ListBox to show file name only?

19 Oct 2017, 11:38

No luck, unfortunately :( It's still showing up the full file path.
GEV
Posts: 1002
Joined: 25 Feb 2014, 00:50

Re: Edit ListBox to show file name only?

19 Oct 2017, 12:02

Code: Select all

#NoEnv
SetTitleMatchMode, 2	; important in this case
SetWorkingDir %A_ScriptDir%
DetectHiddenWindows On
OnExit, CloseS

Menu FileMenu, Add, Exit, MenuHandler
Menu MenuBar, Add, File, :FileMenu
Gui Menu, MenuBar

WinGet, WList,List,ahk_class AutoHotkey
Loop %WList%
{
	Id:=% "WList" A_Index
	WinGetTitle, Title, % "ahk_id " %Id%
	SplitPath, Title, TitleFileName
	TitleFileName := (StrSplit(TitleFileName," - AutoHotkey v").1)
	a.=TitleFileName "|"
}
Gui, Add, ListBox, w400 h100 gClicked vpicked , %a%
Gui, Show, w430 h102, Running Scripts
Return

Clicked:
Gui, Submit
WinClose, %Picked% ahk_class AutoHotkey	; to close script
Return

CloseS:
ExitApp

MenuHandler:
ExitApp

ExitApp
bballjoe12
Posts: 114
Joined: 20 Aug 2017, 09:11

Re: Edit ListBox to show file name only?

19 Oct 2017, 13:14

Works perfect! Thank you!

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat and 281 guests