Hi All,
I have a requirement to list the ".temp" files and its contents using a particular pattern as below:
C:\test\*\servers\*\data\config\*.temp
does dir command supports to use the patterns directly ?
dir C:\test\*\servers\*\data\config\*.temp ( is not working)
Any suggestions ?
Thanks
SS
dir command and wildcards for directories in between
Moderator: DosItHelp
Re: dir command and wildcards for directories in between
This might work:
penpen
Edit: Bugfixed: Added a \* to the "%%~a\servers" string.
Code: Select all
@echo off
for /D %%a in ("C:\test\*") do ^
for /D %%b in ("%%~a\servers\*") do ^
for %%c in ("%%~b\data\config\*.temp") do (
echo(Processing file: "%%~c"
for /F "tokens=* usebackq delims=" %%d in ("%%c") do echo(%%d
echo(
)
penpen
Edit: Bugfixed: Added a \* to the "%%~a\servers" string.
Last edited by penpen on 30 Apr 2014 01:40, edited 1 time in total.
Re: dir command and wildcards for directories in between
Code: Select all
dir /b /s /a-d c:\test\*.temp | findstr /ix "c:[\\]test[\\][^\\]*[\\]servers[\\][^\\]*[\\]data[\\]config[\\][^\\]*\.temp"
Dave Benham
Re: dir command and wildcards for directories in between
Code: Select all
@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%a in ('dir /b /s /a-d c:\test\*.temp') do (
set "name=%%a"
if "!name:\servers\=!" neq "%%a" if "!name:*\data\config\=!" equ "%%~NXa" (
echo Processing file: "%%a"
)
)
Previous method may fail if there is another "\server\" name in another place in the path, but it is unlikely that this happen...
Antonio
Re: dir command and wildcards for directories in between
Thanks for all the replies.
Will try the same and post you the results.
-SS
Will try the same and post you the results.
-SS
Re: dir command and wildcards for directories in between
Hi Antonio,
Thank you.
The below code that you posted has worked for me.
@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%a in ('dir /b /s /a-d c:\test\*.temp') do (
set "name=%%a"
if "!name:\servers\=!" neq "%%a" if "!name:*\data\config\=!" equ "%%~NXa" (
echo Processing file: "%%a"
)
)
Can you please explain what does "if "!name:\servers\=!" neq "%%a"" means ?
what it checks for?
Thanks
SS
Thank you.
The below code that you posted has worked for me.
@echo off
setlocal EnableDelayedExpansion
for /F "delims=" %%a in ('dir /b /s /a-d c:\test\*.temp') do (
set "name=%%a"
if "!name:\servers\=!" neq "%%a" if "!name:*\data\config\=!" equ "%%~NXa" (
echo Processing file: "%%a"
)
)
Can you please explain what does "if "!name:\servers\=!" neq "%%a"" means ?
what it checks for?
Thanks
SS
Re: dir command and wildcards for directories in between
May help you understand it better if you echo those two variables to the screen to see what they are resolving to.
Code: Select all
echo "!name:\servers\=!" is not equal to "%%a"