Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to list all the empty directories using windows batch file?

Tags:

batch-file

I want to create a windows batch file which lists all the empty sub-directories present under the user specified root directory.

Can anybody help regarding the same?

like image 793
Ruhee Jaiswal Avatar asked Mar 27 '12 06:03

Ruhee Jaiswal


1 Answers

@echo off
for /d /r %1 %%A in (.) do (
  dir /a /b "%%~fA" 2>nul | findstr "^" >nul || echo %%~fA
)

The above solution ignores Hidden folders. I've also been told that using both /D and /R options with FOR is bugged, though I've never had a problem with it.


@echo off
dir /a /b %1 2>nul | findstr "^" >nul || echo %%~fA
for /f "eol=: delims=" %%A in ('dir /s /ad /b %1') do (
  dir /a /b "%%~fA" 2>nul | findstr "^" >nul || echo %%~fA
)

The 2nd solution that avoids FOR /D /R will include Hidden folders. But I believe it can fail if folder names contain Unicode.

like image 160
dbenham Avatar answered Oct 23 '22 21:10

dbenham