Question on NOT traversing subdirectories with DO

May 23, 2010
54
1
Seattle
I don't know whether this is intentional DO behavior. The documentation states that the /D option (specify a starting directory) is for use with the /S option (traverse subdirectories). The /D option may be specified without the /S option, without error. However, in this case it is ignored. In other words, there's no way to say "start in this other directory, but do not traverse subdirectories." WAD or not?
Code:
[C:\batch]do file in /d"h:\" image* (echo %file (in %_cwd))
imagehelp.btm (in C:\batch)

[C:\batch]do file in /d"h:\" /s image* (echo %file (in %_cwd))
Image1.jpg (in H:\)
Image10.jpg (in H:\)
image2.jpg (in H:\)
image20.jpg (in H:\)
It's easy enough to guard against with surrounding code, but I thought I'd ask.
 
May 20, 2008
11,619
110
Syracuse, NY, USA
Hmmm! I thought "/s0" would do it but it doesn't (acts like "/s"). "/s0" works for DIR. Is this a bug?
 
May 23, 2010
54
1
Seattle
Yes, that does work. But you definitely do not want to use the /s option with that syntax, because it will traverse the current directory, not the named one:
Code:
[C:\batch]do file in /s h:\image* (echo %file^t^t%_cwd)
H:\Image1.jpg           C:\batch
H:\Image10.jpg          C:\batch
H:\image2.jpg           C:\batch
H:\image20.jpg          C:\batch
H:\Image1.jpg           C:\batch\Alan
H:\Image10.jpg          C:\batch\Alan
H:\image2.jpg           C:\batch\Alan
H:\image20.jpg          C:\batch\Alan
H:\Image1.jpg           C:\batch\BAT
H:\Image10.jpg          C:\batch\BAT
H:\image2.jpg           C:\batch\BAT
H:\image20.jpg          C:\batch\BAT
H:\Image1.jpg           C:\batch\CharlesG
H:\Image10.jpg          C:\batch\CharlesG
...
Which, I suppose, agrees with the documentation. But the inconsistency noted in post #1 is still there.
 

rconn

Administrator
Staff member
May 14, 2008
12,420
152
I don't know whether this is intentional DO behavior. The documentation states that the /D option (specify a starting directory) is for use with the /S option (traverse subdirectories). The /D option may be specified without the /S option, without error. However, in this case it is ignored. In other words, there's no way to say "start in this other directory, but do not traverse subdirectories." WAD or not?

WAD, because it wouldn't save any effort vs. just doing a CDD first. DO /D will only work with a matching /S.

I think you're misinterpreting the /D - it does not mean "start the DO processing in this directory", it means "start the recursion in this directory".
 
Aug 23, 2010
662
9
The help is written in a way that separates /D and /S parameters, and even make the /D switch appear required where all other parameters are optional.
I, too, was hit by this issue just now.
 

Similar threads