Despite it is not documented pushd
accepts wildcards (when command extensions are turned on). But does not work as I expect and seems buggy. When a wildcard expression is passed pushd gets all files(!) and folders that apply the pattern in alphabetical order and tries to enter the first item in the list - without checking if it is folder or file:
C:>break>a1
C:>md a2
C:>pushd "a*"
The directory name is invalid.
C:>md b1
C:>pushd "b>"
C:\b1>
Is there way to force pushd
to enter the first directory that is like the passed the wildcard expression.Things like b*\
or b*\nul
does not work.
Looks like the only way is to list directories with DIR
command, to get the first one and then pass it to the pushd
:
@echo off
set "mask=b?"
for /f "tokens=*" %%# in ('dir /b /a:d /o:-n "%mask%"') do @set the_dir=%%#
pushd %the_dir%
But this does not look convenient for usage from command line.