How to? List empty folders

Apr 2, 2011
1,442
10
54
North Carolina, USA
I tried

DEL /a:d /e /s /x /n /y * but that said 0 files were deleted.

Any suggestions or should I make a suggestion on the feedback forum?
 
Apr 13, 2010
310
7
61
The Hague
If you want to list empty folders then why are you trying to DELete something. If you want to delete directories, use RD. If you want to list directories have a look at TREE. Of course DIR /A:D /S will also list directories but that gives you no information about any files in them. If you want to do that, you can use the list of directories DIR ... selects for you in a DO loop and test the contents of each directory on your criteria.

Going back to your example, DEL /S /X * will delete all files and remove any empty directories afterwards. Remember that DEL is file oriented so you might say that with the "convenience" option /X the directories are removed as a side-effect. If it is directories you want to remove, without any concern about the files they contain, then RD /S * would be more "appropriate".

Hope this helps,
DJ
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
If you want to list empty folders then why are you trying to DELete something.

He's not. DEL /N deletes Nothing. He's using a variant on a common trick to remove empty directories, in the hope that DEL will list the empty directories it would remove. Clever. But DEL does not list directories, only files, so the creativity is wasted.
 
Apr 13, 2010
310
7
61
The Hague
This works.

Code:
do d in /p dir /a:d /s /f /h * ( if %@files[/h %d] == 0 echo %d )

Or multi-line

Code:
do d in /p dir /a:d /s /f /h *
   iff %@files[/h %d] == 0 then
      echo %d
   endiff
enddo
 
Dec 7, 2009
238
2
Left Coast, USA
I had a look at the online help -- specifically the '/s' switch for 'rd' -- and was appropriately terrified. Egad.

Just by the by:

> global /i /q if %@files[/h *] == 0 echo %_cwd

Why is that 'fairly hideous'? (see earlier in thread) It seems to me it's precisely the sort of thing where TCC excels, when you need something done effectively with the least strain.
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
> global /i /q if %@files[/h *] == 0 echo %_cwd

Why is that 'fairly hideous'? (see earlier in thread)

Eh, I don't love GLOBAL. It's a crocky little command for adding recursion to externals which don't support it, and it works by changing the current working directory n times; kludgey at best.

DJ's approach is more elegant. But there really ought to be a way to do it without the DIR and implicit pipe....
 

Charles Dye

Super Moderator
Staff member
May 20, 2008
4,469
88
Albuquerque, NM
prospero.unm.edu
Another bodge, this time using FOR:

Code:
for /r %d in ( nul ) if %@files[/h "%d\.."] == 0 echo %@path[%d]

It seems like FOR /R /D would be perfect for this purpose, but it doesn't return the current directory, only its subdirectories.
 
May 20, 2008
11,437
99
Syracuse, NY, USA
4UTILS has:
Code:
@EMPTY[dir] = 1 (empty), 0 (non-empty), -1 (error), -2 (not found)
It simplifies things a tad. But you'll still have to use a TCC mechanism for traversing the tree. I like GLOBAL for this particular task because it doesn't let you in places you don't belong in while suppressing error messages. While it's not elegant, here's my $.02.
Code:
global /i /q if %@empty[.] == 1 echo %_cwd
 
May 20, 2008
11,437
99
Syracuse, NY, USA
I (Charles too) should have used "/H" with GLOBAL.
Code:
global /h /i /q if %@empty[.] == 1 echo %_cwd
With that, I find 707 empty directories on my system drive, 765 if elevated!
 
May 20, 2008
11,437
99
Syracuse, NY, USA
Yes.

I note that "empty directory" can mean different things: no files in the directory itself, no files in the directory or any of its subdirectories, no files or subdirectories (other than the . and .. entries) at all.
If it has subdirectories, I wouldn't even be tempted to call it empty.
 
Apr 2, 2011
1,442
10
54
North Carolina, USA
As the OP - I wanted to see the list of folders which have no files in that or any subfolder.
 
Aug 3, 2016
376
9
Netherlands
Code:
ATTRIB /D /S * 1>nul 2> empty.txt

Output is something like:
Code:
TCC: (Sys) There are no more files.
 "C:\Temp\TCMD20\plugins\*"
TCC: (Sys) There are no more files.
 "C:\Temp\TEST_TCMD\ff\*"
TCC: (Sys) There are no more files.
 "C:\Temp\TEST_TCMD\ProfileManager\*"
TCC: (Sys) There are no more files.
 "C:\Temp\TEST_TCMD\test1\*"
TCC: (Sys) There are no more files.
 "C:\Temp\WebServer2\LightTPD\logs\*"

So it needs a little post-processing, depending on what you want to do with those directories. That can be done with -for example- findstr /i /v "TCC:" empty.txt or TPIPE /grep .. /replace ... )
But the directory parsing is straightforward (and fast! :-)
 
Last edited:
Apr 2, 2011
1,442
10
54
North Carolina, USA
Code:
for each dir (do not transverse junctions (either soft or hard))
  if it has no subdirs
  if it has 0 files
  list %_CWD
endfor
 
Aug 3, 2016
376
9
Netherlands
[...]So it needs a little post-processing [...]

I want to get myself a little more familiar with sed, awk, grep and the likes and thought this was a good opportunity to dust off SED:
Code:
ssed.exe -e /^TCC.*denied.$/{;N;d} -e /^TCC:.*files.$/d -e s/\\\*// empty.txt

In TCC you have to escape the ^:
Code:
ssed.exe -e /^^TCC.*denied.$/{;N;d} -e /^^TCC:.*files.$/d -e s/\\\*// empty.txt
(looks like a cat walked on my keyboard ;-)

PS: Feel free to improve upon this code (Still have a lot to learn; this is just the 4th time I used SED and those times were so far apart that I basically had to start from zero).

PPS: You could also use this to report the folders you don't have access to: switch the "denied" and "files" text.
 
Last edited:
Similar threads
Thread starter Title Forum Replies Date
D LIST command wierdness with empty Unicode file Support 1
FreezerBurnt ANSI Prompt messes up list output. Support 39
Phileosophos PDIR to list filenames without extensions? Support 2
T Is there a way to maintain the position in the environment list, while debugging? Support 10
Alpengreis List command: text truncated in find box (german) Support 9
L LIST's pop-up search loses focus in a Windows Terminal window Support 15
A List windows with titles matching given pattern? Support 2
C How to make list of drive contents when shutdown PC / Everything.exe Support 7
D _USBS list misses flash drives that @USB recognizes. Support 7
Phileosophos LIST edit not invoking my specified editor Support 4
cxxl WAD Mouse movement sluggish when using TCC list Support 3
Oz Solomon Problem with "list" Support 14
P Strange mouse behavior with list Support 2
T Invalid attach tabs list Support 10
M A list of issues .. Support 17
J Documentation New help system: "skip word list" Support 11
WavSlave Fixed LIST /U not working in TCC v19 Support 5
R V19 - At startup, TCC save directory in the directory history list Support 2
C cosmetic issue with LIST's (I) Support 9
Stefano Piccardi list of TCC commands for external editors Support 4
vefatica Get a list of all files with alternate streams? Support 11
Joe Caverly LIST /T (search for Text) Support 2
Joe Caverly ListColors for LIST Support 1
M How to? List path getting short file and directory names... Support 10
S How to? Use wild cards in include list without duplicate processing Support 49
vefatica Fixed No text in List View! Support 4
D Folder/List view changed in v15 Support 8
S list seems to loose focus v15 Support 2
A How to? Filter history list with unicode chars Support 0
N WAD Take Command and UNCs for Folder List Support 10
S TCMD No List-View with Libraries? Support 5
M Sync folder/list view with command window? Support 2
vefatica New directory not moved to end of list Support 2
vefatica LIST and TYPE show UTF8 BOM Support 4
M Problem with the "List" command... Support 19
vefatica DO f in /L <list of file names>? Support 6
C list jpsoft file Support 2
A How to? Filter a list by numeric number within filename Support 28
M Just an out-of-curiosity question the List command vs. the @Lines function... Support 13
Dmitry L. Kobyakov Fixed The Take Command File List Panel shows 0 for all file sizes at DVD Support 4
M WAD A case where the "List" command is clearly not working at all... Support 4
Joe Caverly LIST scrollbar Support 2
R TC 13 / you forgot to list a new feature Support 2
S BDEBUGER: watch list limit? Support 4
T "L" (LIST) not working in TCC's examples.btm Support 3
rconn Suggestion list for next major version Support 0
M FFIND and LIST does not work for UTF-8 fles Support 10
JohnQSmith List View refresh Support 6
S Using TCC list with KatMouse Support 9
S "List" decoding problem And TCMD crash. Support 0

Similar threads