Page 1 of 1

Opening file using Wildcards

Posted: 03 Aug 2012 04:31
by Raymondo
batch file wildcards i have to open a file but there are two very similar ones and i only open one.

say i have two documents that are the same like
This_is_a_test_v10.02.03.00.txt
This_is_a_test_v10.02.03.00_hello.txt

i only want to open the top one and not the bottom one.

this is what i have so far

Code: Select all

For /f "usebackq tokens=*" %%I in (`dir /b /a-d "%filepath%\This_is_a_test*.txt"`) do start notepad "%filepath%\%%I"


Thank you

Re: Opening file using Wildcards

Posted: 03 Aug 2012 06:07
by foxidrive

Code: Select all

@echo off
pushd "%filepath%"
For /f "delims=" %%a in ('dir /b /a-d "This_is_a_test*.txt"') do (
start "" notepad "%%a"
goto :next
)
:next
popd

Re: Opening file using Wildcards

Posted: 03 Aug 2012 07:00
by Raymondo
Awesome thanks that is perfect