I want to find a folder whose name starts fld-.
FOR lets me use wildcards:
for /D %%f in ("fld-*") do set FOLDER=%%f
However, with the following folders:
.fld-blah\ fld-blahblah\ afld-blah\
it also (somewhat unexpectedly) finds the one starting, ".".
I decided to test the first char using the DOS LEFT operator. This doesn't seem to work on
FOR variables (the
%%F here), so I need to assign it to a normal variable first. Running the following
.bat file twice (you'll see why):
@echo off for /D %%f in ("fld-*") do ( set TEST=%%f echo f: %%f echo TEST: %TEST% echo TEST[0,1]: %TEST:~0,1% echo. )
produces the following output:
C:\Users\Bob\Desktop\test>test.bat f: fld-blahblah TEST: TEST[0,1]: ~0,1 f: .fld-blah TEST: TEST[0,1]: ~0,1 C:\Users\Bob\Desktop\test>test.bat f: fld-blahblah TEST: .fld-blah TEST[0,1]: . f: .fld-blah TEST: .fld-blah TEST[0,1]: .
TEST appears only to be assigned after the
(...) group of commands completes.
So. Can anyone tell me:
- Whether I can make the
forwildcard ignore folder names that start with a dot?
- Whether there is syntax I can use to apply the
LEFToperator to the
- Whether there is a way I can assign a variable AND use it within a
- Whether there is some other method I can use to achieve my goal (within DOS, I know I can use Powershell, cygwin, etc.)?