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

后端 未结 1 510
太阳男子
太阳男子 2020-12-11 02:38

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?

相关标签:
1条回答
  • 2020-12-11 03:03
    @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.

    0 讨论(0)
提交回复
热议问题