How to use multi-line DO to loop through first level directory names

Feb 26, 2017
4
0
I'm using TCMDv27 on Windows 10 20H2 and trying to create a multi-line DO loop that loops through all of the first level subdirectory names in a targeted directory that I give it. But I cannot figure out what syntax to use to accomplish this. So assuming the directories involved are

Z:\Audio
+--CD
+--HD
+--MP3
I want to give the loop "Z:\Audio" and have its loop variable contain "CD", "HD", and "MP3" as it loops. The rest of the multi-line loop will do some processing with those subdirectory names.

I've been referring to the helpfile syntax below as the closest syntax I could find that might do this:
DO varname IN [range...] /D"directory" [/I:"text" /S[[+]n] /A:[[-|+]rhsadecijopt /O:[-]acdeginorstuz fileset [(command)]

But it's unclear how to accomplish this. What I'm currently using is

DO F in Music:\Audio\*
IF NOT ISDIR "%F" ITERATE
other processing
ENDDO

Note that Music: is a directory alias for a drive\directory combination.

But I'd like not to have to use the IF NOT ISDIR line because if the targeted directory has many files, the script will spend time iterating past all the files. Is there no way to tell DO just to process directories? I tried adding the /A:d switch but that didn't work.

TIA
David
 

samintz

Scott Mintz
May 20, 2008
1,503
16
Solon, OH, USA
Use it like this:
Code:
$ do d in /a:d * (echo %d)
.RaRecovery
FamilyKeys
SystemManifests
If you specify a path instead of a generic wildcard, e.g. c:\Windows\*, then %d will contain the full path. If you only want the names without the path, then use %@filename[%d] instead of just %d.

Another oddity of DO is when you recurse into subfolders there are no paths.
Code:
[C:\TC27]
$ do d in /a:d /s * (echo %d)
event
library
sdk
styles
.cov
ipch
Release
synctest
x64
event-76870a50
Release
Win32
x64

Each of the subfolders are listed then as filenames only.
 
  • Like
Reactions: dealio
Feb 26, 2017
4
0
Thanks Charles! That worked, as I"m sure you're not surprised! But I'm thrilled to finally get it to work. I guess I just don't understand how to read the syntax help in the help file. I tried lots before coming here and nothing worked consistently. So thanks again.

Since we're on the topic, if I were to want to recurse through directories, for example in that same tree above, assuming there are subdirectories below the ones I gave, what would be the proper syntax to do that? I like the /S capability and can see some good uses for it, but haven't gotten it to work.

Thanks
David
 
Feb 26, 2017
4
0
Use it like this:
Code:
$ do d in /a:d * (echo %d)
.RaRecovery
FamilyKeys
SystemManifests
If you specify a path instead of a generic wildcard, e.g. c:\Windows\*, then %d will contain the full path. If you only want the names without the path, then use %@filename[%d] instead of just %d.

Another oddity of DO is when you recurse into subfolders there are no paths.
Code:
[C:\TC27]
$ do d in /a:d /s * (echo %d)
event
library
sdk
styles
.cov
ipch
Release
synctest
x64
event-76870a50
Release
Win32
x64

Each of the subfolders are listed then as filenames only.
Thanks Scott! Very helpful. You must have been posting this while I was posting a question about exactly this topic - recursing through subdirectories. Have you tried using /Sn as in /S1, /S3, /S0 switches? Are there special requirements to get them to work (quirks)?
 
Feb 26, 2017
4
0
Try the syntax below. It generates full directory paths:

Code:
do d in /a:d /s * (echo %@FULL[%d])
 
Similar threads
Thread starter Title Forum Replies Date
vefatica FFIND and multi-line regular expressions Support 4
B Alias with multi line definitions not assigned Support 6
T Fixed multi-line alias issue Support 13
vefatica Single-line DO inside nested multi-line DOs? Support 9
rps Multi-column DIR /v not displaying all files. Support 5
D xp support and multi-license Support 5
T WAD Difference between TCC and CMD in handling multi-command lines Support 6
V V - Multi-Pane File Manager Support 14
Daniel P How to Purchase a Multi-System License for TCC? Support 2
T Closing multi-tab TCMD crashes Support 4
D Individual vs multi-system licenses Support 1
C Language setup files, to use in creating similar for Multi-Edit Support 2
C How to? Multi-Display Configuration Support 5
C multi-INI file merging Support 1
T VIEW only works from command line Support 14
vefatica `Back quotes` - command line vs. batch file Support 5
Phileosophos Is there any way to open the Take Command options dialog from the command line? Support 8
Phileosophos Command-line Editing Shortkeys That Fail Support 6
D Open Windows 10 Photos app from command line Support 11
Peter Murschall Single-line Do-CMD is a bit uncooperative. Support 6
Jesse Heines Strange Line Wrapping Behavior Support 14
fpefpe How to? command echo in title line/bar Support 2
vefatica Command line DO with no closing parenthesis? Support 9
R Long commands retrieved from command history have blank line when wrapped Support 20
M No line wraps if last line of the screen buffer is reached Support 5
Joe Caverly No blank line in TEXT...ENDTEXT in a LIBRARY function Support 8
R CMDebug, dark theme, current line Support 7
vefatica IDE - when breakpoint is on a blank line? Support 3
D Double Quote in TC Tool Bar Button Command line Support 3
Joe Caverly Expand all aliases on the command line Support 2
vefatica How do I do this with a multiple-line DO? Support 7
Jay Sage Cannot Postion Cursor in Command Line Using Mouse Support 7
vefatica Windows 10 and line wrapping selection? Support 6
vefatica IDE.EXE's command line? Support 19
x13 TPIPE /REPLACE - Remove line (including EOL) Support 3
D btm file command line augments comparing for string or math. Support 12
D Grabbing html text with @line Support 3
Chen Touboul Overtyping issue - i press the Insert key, help till press enter for new line in TCC Support 2
P Escape key no longer clears command line in v24 Support 21
J File explorer handling from command line? Support 2
M Ctrl-C when using command line history does nothing Support 2
M Command line parsing differences between cmd.exe and TCC Support 6
C Replace 1st argument on command line Support 4
vefatica Library functions and line continuations? Support 4
Joe Caverly Works in debugger, not from cmd line Support 1
P No linefeed on last line of console window Support 2
K Command Line Selection Not Working Support 12
J Error running Python at command line Support 9
Joe Caverly PSHELL Blank Line Display Support 2
rps How to? Alias/Command line use of *log on/off Support 2

Similar threads