list certain extensions only

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
macroman
Pro Scripter
Posts: 91
Joined: Mon Jun 02, 2014 5:32 am

list certain extensions only

Post by macroman » Wed Jun 08, 2016 11:25 pm

Hello all,

How do get a list of files with certain file extensions only? The line i'm using now is

Code: Select all

GetFileList>c:\temp\*.*,files 
I just want to list .bat .exe and .com only...

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Re: list certain extensions only

Post by JRL » Thu Jun 09, 2016 4:24 am

Code: Select all

GetFileList>c:\temp\*.bat,vBATfiles,crlf
GetFileList>c:\temp\*.exe,vEXEfiles,crlf
GetFileList>c:\temp\*.com,vCOMfiles,crlf

Let>vAllFiles=%vBATFiles%%vEXEfiles%%vCOMfiles%

MDL>vAllFiles

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: list certain extensions only

Post by hagchr » Thu Jun 09, 2016 5:29 am

Hi, my solution was very similar, however kept the ; as delimiter. For a general solution one could put the extensions into a string, eg Let>str=exe;bat;com... , then parse with Separate> and loop. Alternative put it into a SRT> with desirable extensions as parameter.

Code: Select all

Let>path=c:\temp\

GetFileList>%path%*.exe,files1
GetFileList>%path%*.com,files2
GetFileList>%path%*.bat,files3
Let>Files=%files1%;%files2%;%files3%

//Replace any multiple ; with just one ;
RegEx>;+,Files,0,m,nm,1,;,Files
//Remove any initial or final ;
RegEx>(^;|;$),Files,0,m,nm,1,,Files

MDL>Files

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: list certain extensions only

Post by hagchr » Thu Jun 09, 2016 7:07 am

Overkill here, but I was just curious how one could do it in the DOS world. From strList one can easily extract the file info.

Code: Select all

IfFileExists>%TEMP_DIR%tmplist.txt
    DeleteFile>%TEMP_DIR%tmplist.txt
Endif

Let>string=*.exe *.bat *.com

ChangeDirectory>c:\temp\

Let>RP_WAIT=1
Run>cmd /C dir %string% >> "%TEMP_DIR%tmplist.txt"

ReadFile>%TEMP_DIR%tmplist.txt,strList
MDL>strList

macroman
Pro Scripter
Posts: 91
Joined: Mon Jun 02, 2014 5:32 am

Re: list certain extensions only

Post by macroman » Sun Jun 12, 2016 8:55 am

JRL wrote:

Code: Select all

GetFileList>c:\temp\*.bat,vBATfiles,crlf
GetFileList>c:\temp\*.exe,vEXEfiles,crlf
GetFileList>c:\temp\*.com,vCOMfiles,crlf

Let>vAllFiles=%vBATFiles%%vEXEfiles%%vCOMfiles%

MDL>vAllFiles
Thank you you're the best!

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: list certain extensions only

Post by hagchr » Sun Jun 12, 2016 10:30 am

Hi, just be aware that if you don't have a delimiter between the file groups when you put them together, you may get problem eg with Separate> not separating as you want, possibly showing elements with more than one file in them. Depends on what you are doing later if problem or not.

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts