[SOLVED] Show multiple extensions in Gui Listview Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
timoshina
Posts: 28
Joined: 06 Jun 2017, 12:45

[SOLVED] Show multiple extensions in Gui Listview

17 May 2018, 14:03

Fellas, where can I specify which file extensions I want to show in my list?
For example txt, docx, jpg

Code: Select all

Gui, Add, ListView, x5 y5 w200 h350 gLiveList, ==Desktop Files==
Gui, Show, NoActivate

folderdir = %A_Desktop%\*.*
fileext = *
settimer,aaa, 5000

LB:
LV_Delete()
Loop, %folderdir%*.%fileext%
   LV_Add("", A_LoopFileName)
return


LiveList:
if A_GuiEvent
return


aaa:
gosub,LB
return
User avatar
TLM
Posts: 1323
Joined: 01 Oct 2013, 07:52

Re: Show multiple extensions in Gui Listview

17 May 2018, 14:13

try something like

Code: Select all

fileExtensions = txt, docx, jpg ; << create a list of white listed extensions, place at or near top of script
;......................
LB:
LV_Delete()
Loop, %folderdir%*.%fileext%
{
	; add the below condition
	if ( InStr( fileExtensions, fileext ) )
	{
		LV_Add("", A_LoopFileName)
	}
}
I just eyeballed so no guarantee it's exactly what you're after.
timoshina
Posts: 28
Joined: 06 Jun 2017, 12:45

Re: Show multiple extensions in Gui Listview

17 May 2018, 14:27

TLM wrote:try something like

Code: Select all

fileExtensions = txt, docx, jpg ; << create a list of white listed extensions, place at or near top of script
;......................
LB:
LV_Delete()
Loop, %folderdir%*.%fileext%
{
	; add the below condition
	if ( InStr( fileExtensions, fileext ) )
	{
		LV_Add("", A_LoopFileName)
	}
}
I just eyeballed so no guarantee it's exactly what you're after.
I appreciate fast answer but unfortunately something is missing. Now it doesn't show any files at all.
timoshina
Posts: 28
Joined: 06 Jun 2017, 12:45

Re: Show multiple extensions in Gui Listview

17 May 2018, 15:01

ok I think I got it and It seems to work. :) Hope this is the proper way to go

Code: Select all

Gui, Add, ListView, x5 y5 w200 h350 gLiveList, ==Desktop Files==
Gui, Show, NoActivate
settimer,aaa, 5000

LB:
LV_Delete()
Loop, %A_Desktop%\*.txt
   LV_Add("", A_LoopFileName)
Loop, %A_Desktop%\*.jpg
   LV_Add("", A_LoopFileName)
Loop, %A_Desktop%\*.docx
   LV_Add("", A_LoopFileName)
return


LiveList:
if A_GuiEvent
return


aaa:
gosub,LB
return
timoshina
Posts: 28
Joined: 06 Jun 2017, 12:45

Re: Show multiple extensions in Gui Listview

17 May 2018, 15:25

Funny thing the code above works in windows 10 but does not work in windows 7 (only shows first loop). Question is still open then :|
User avatar
TLM
Posts: 1323
Joined: 01 Oct 2013, 07:52

Re: Show multiple extensions in Gui Listview  Topic is solved

17 May 2018, 15:34

This works for me on all OS's

Code: Select all

fileExtensions = txt jpg docx

Loop, %A_Desktop%\*.*
{
	if ( InStr( fileExtensions, A_LoopFileExt ) ) 
		msgbox % A_LoopFileFullPath
}
Obviously you'd have to change the message box to you ListView command.

You only have to loop through the files once.
timoshina
Posts: 28
Joined: 06 Jun 2017, 12:45

Re: Show multiple extensions in Gui Listview

17 May 2018, 16:25

Thank you, TLM!

Here is the final code

Code: Select all

Gui, Add, ListView, x5 y5 w200 h350 gLiveList, ==Desktop Files==
Gui, Show
settimer,aaa, 3000  ;updates file list every 3 seconds

fileExtensions = txt jpg docx

LB:
LV_Delete()
Loop, %A_Desktop%\*.*
   if ( InStr( fileExtensions, A_LoopFileExt ) ) 
   LV_Add("", A_LoopFileName)
return 

LiveList:
if A_GuiEvent
return

aaa:
gosub,LB
return

GuiClose:
ExitApp

Return to “Ask For Help”

Who is online

Users browsing this forum: codude, FanaticGuru, Google [Bot], KiritoSanPlays, MannyKSoSo, Quadzilla, TehCreepN1 and 34 guests