Make a list of empty folders

Page 1 of 2 12 LastLast

  1. Posts : 124
    Windows 10
       #1

    Make a list of empty folders


    Hi

    I want to make a spreadsheet of (the full path statements of) all empty folders on a drive (external, USB). I have googled and found 4 or 5 suggestions on how to do this, but couldn't get any of them to work.

    - - -

    Alternatively, some kind of DIR statement that gives the Path statements (of folders, not files) suffixed with EITHER the Number-of-Files OR the Size-in-KB for each folder. Those two/three fields preferably on the same line, with some kind of delineator, so I can dump it into a spreadsheet and filter out anything non-zero. e.g.

    E:\First Level, Folder 1\Second Level, Folder 1\ 246 56KB
    E:\First Level, Folder 1\Second Level, Folder 2\ 97,843 1,864KB
    E:\First Level, Folder 1\Second Level, Folder 3\ 0 0KB

    Karen's Directory Printer utility would usually do this, but it bombs-out if the task is too big.

    I am aware that there are utilities that will find and delete folders, but I haven't found one that will output a list.

    Windows 10 Home, latest.
      My Computer


  2. Posts : 43,022
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #2

    Hi, it looks as if Option 2 allows you to create a list. I've not tried it myself.
    7 Tools To Find And Delete Empty Folders in Windows • Raymond.CC

    (Option 'Save checked paths to text file').
      My Computers


  3. Posts : 124
    Windows 10
    Thread Starter
       #3

    Yes, that seems to work nicely, thanks for the sleuthing ! I think I've seen that page, but didn't see the 'Save checked paths to text file' part.
      My Computer


  4. Posts : 124
    Windows 10
    Thread Starter
       #4

    Hmm

    Seems I spoke too soon. EmptyFolderNuker is fine for smaller samples, but when the number of empty folders gets into the hundreds, then the text-export fails and only prints the first ten lines

    Any other thoughts/suggestions welcome, thanks :)
      My Computer


  5. Posts : 43,022
    Win 10 Pro (22H2) (2nd PC is 22H2)
       #5

    Given that two are failing, could it be that something is tripping them up?
    Have you looked at how they are failing, or considered whether they are failing at the same point?

    Try running
    chkdsk x: /scan
    where x is the drive letter in question.

    Any permission or protection issues?

    Also consider booting to Safe Mode and then trying.
      My Computers


  6. Posts : 456
    Windows 10
       #6

    I think I can do batch script that shows all "Empty Folders" but I don't know what your expectations are.

    For example if you have:

    Parent Folder \ Empty Subfolder 1 \ Empty Subfolder 2 \ Empty Subfolder 3 \ Empty Subfolder 4

    Only "Empty Subfolder 4" would be really Empty because if a folder has a subfolder in it, it can not be empty, only the last subfolder in a chain of subfolders can be "really empty" got what I mean?

    So here is the question are you looking for a way to "see all empty folders" or "All folders that only have empty Subfolders"?
      My Computer


  7. Posts : 124
    Windows 10
    Thread Starter
       #7

    dalchina said:
    Given that two are failing, could it be that something is tripping them up?
    I don't think so, EmptyFolderNuker sees/counts/lists the empty folders as expected in the GUI. It's the 'export to text file' part that has the problem. On three different disks:
    Disk06 (external HDD USB3) GUI sees 14,500 empty folders; prints only 9
    Disk07 (external HDD USB3) GUI sees 6335 empty folders; prints 756
    DiskD (internal SSD) GUI sees 1544 empty folders; prints 1085.

    Disk 06 (the one I'm working on) is OK on CHKDSK. Results are all the same in Win SafeMode (except that it takes 6 hours to run rather than 10 minutes!!).

    --
    I've been using 'Karen's Directory Printer' utility for years and it often Hangs if the job is too big (then dir /b /s /a:-D >textfile.txt works fine on the same data). I assume that it's some kinda memory problem with the app (??)
    . There's no correlation between the point of failure between Karen's Directory Printer and EmptyFolderNuker; and no obvious signs of problem at the point of fail ::
    EDIT: edit - sorry, it turns-out that the EmptyFolderNuker export is quitting when it first encounters a UTF character (asian language) or some weird stretched hyphen, —. I can't do without UTF-8 support, I'm afraid. (the EmptyFolderNuker export/save dialog has no other encoding options than plain (??ANSI) .txt


    I

    - - - Updated - - -

    ricardobohner said:
    So here is the question are you looking for a way to "see all empty folders" or "All folders that only have empty Subfolders"?
    Hi

    thanks - either would be fine, tbh. As long as I get the full path statement for the lowest level/truly empty folder.

    I am trying to compare five different versions of the same dataset (website spiders containing thousands of folders; which various different people have tried to tidy-up (remove genuinely redundant files) in a variety of various ways.

    So whichever method you can do is fine, as it will be applied consistently across all different versions and is just the start-point for a manual audit of which parts to salvage from which version.

    If it's possible to also show the higher level folders that contain other empty folders, that would be great, but isn't necessary.

    EDIT: Sorry - just found out that it must support UTF-8 characters.
    if it helps, "CMD.EXE /u" invokes UTF support in DIR commands

    thanks
    Last edited by BobSter2; 04 Jul 2021 at 16:04.
      My Computer


  8. Posts : 456
    Windows 10
       #8

    It seems Windows 10 saves as UTF-8 by default. Let me know of any bugs...



    Code:
    @echo off
    chcp 1252 > Nul
    Title Find Empty Folders
    setlocal EnableDelayedExpansion
    
    IF /i exist "%~1" (set "CAtual=%~1") else (set "CAtual=%~dp0")
    
    :Inicio
    
    cls
    echo.
    echo What would you like to do?
    echo.
    echo  1. Delete Empty Subfolders
    echo.
    echo  2. Show Empty Folders
    echo.
    echo  3. Show Folders that only have Empty Subfolders
    echo.
    echo  4. Exit
    echo.
    echo.
    set /p "Resposta=Answer: 1 / 2 / 3 / 4: "
    
    if /i "%Resposta%"=="1" goto :Opcao1
    if /i "%Resposta%"=="2" goto :Opcao2
    if /i "%Resposta%"=="3" goto :Opcao3
    if /i "%Resposta%"=="4" goto :Opcao4
    
    :Opcao1
    cls
    echo.
    echo  Specify a path or press Enter to use current path: 
    echo.
    echo Current Path: %CAtual%
    echo.
    set /p "Caminho=Path: "
    set Caminho=%Caminho:"=%
    if not Defined Caminho (set "Caminho=%CAtual%") else (set "CAtual=%Caminho%")
    
    echo.
    for /f "Delims=" %%a in ('dir /b /ad /s "%Caminho%" ^|sort /r') do dir /a /b "%%a" | Find /i /v ""> Nul 2>&1 || Rd "%%a"
    goto :Inicio
    
    :Opcao2
    cls
    echo.
    echo  Specify a path or press Enter to use current path: 
    echo.
    echo Current Path: !CAtual!
    echo.
    set /p "Caminho=Path: "
    set Caminho=%Caminho:"=%
    
    if not Defined Caminho (set "Caminho=%CAtual%") else (set "CAtual=%Caminho%")
    
    echo Empty Folders:>Empty.txt
    echo.>>Empty.txt
    for /f "Delims=" %%a in ('dir /b /ad /s "%Caminho%" ^|sort /r') do dir /a /b "%%a" | Find /i /v "" 1> Nul 2> nul || echo %%a>>"Empty.txt"
    notepad "Empty.txt"
    goto :Inicio
    
    :Opcao3
    cls	
    echo.
    echo  Specify a path or press Enter to use current path: 
    echo.
    echo Current Path: %CAtual%
    echo.
    set /p "Caminho=Path: "
    set Caminho=%Caminho:"=%
    if not Defined Caminho (set "Caminho=%CAtual%") else (set "CAtual=%Caminho%")
    
    echo Folders With Files:>FoldersWithFiles.txt
    echo.>>FoldersWithFiles.txt
    echo Folders With Empty Subfolders:>EmptySub.txt
    echo.>>EmptySub.txt
    for /f "Delims=" %%a in ('dir /b /a:-d /s "%Caminho%"') do find "%%~dpa" FoldersWithFiles.txt 2> nul 1> nul || >> FoldersWithFiles.txt echo %%~dpa
    for /f "Delims=" %%a in ('dir /b /a:d /s "%Caminho%"') do Find "%%a\" FoldersWithFiles.txt 2> nul 1> nul || >> EmptySub.txt echo/%%a
    notepad EmptySub.txt
    goto :Inicio
    
    :Opcao4
    exit
      My Computer


  9. Posts : 124
    Windows 10
    Thread Starter
       #9

    Thanks for this it is awesome - especially the high speed and the friendly UI !

    There is a problem with rendering the unicode characters tho'.
    A path
    d:\test\1\2\3 (all 'empty' folders, no files)
    ...gets reported fine, but the same thing in asian languages, e.g.

    D:\test\๑\๒\๓
    D:\test\၁\၂\၃
    D:\test\一\二\三

    ...all get reported as D:\test\?\?\?

    This is true even when having added 'cmd.exe /u /c' at the start of the code, as you suggest for other OSs. (I am using Windows 10)

    Your outputted text files are marked as being UTF-8, but the unicode characters are not rendered correctly.

    ====

    by way of diagnostics

    if I open a regular command line window and run
    dir /s /b >0FilesAndFoldersList.txt
    .. the resulting file shows
    D:\test\1
    D:\test\?
    D:\test\?
    D:\test\?
    D:\test\1\2
    D:\test\1\2\3
    D:\test\?\?
    D:\test\?\?\?
    D:\test\?\?
    D:\test\?\?\?
    D:\test\?\?
    D:\test\?\?\?
    The text file is marked as being UTF-8

    however, if I run
    cmd.exe /u
    dir /s /b >0FilesAndFoldersList.txt
    .. the file renders the characters correctly, saying:
    D:\test\1
    D:\test\๑
    D:\test\၁
    D:\test\一
    D:\test\1\2
    D:\test\1\2\3
    D:\test\๑\๒
    D:\test\๑\๒\๓
    D:\test\၁\၂
    D:\test\၁\၂\၃
    D:\test\一\二
    D:\test\一\二\三
    The text file is marked as UTF 16-LE
    If I Save-As that textfile to UTF-8, there is no change in its appearance - the characters get rendered just fine in the UTF-8 version.

    (In all cases, the on-screen console window displays the unicode characters as question marks (which is fine, it is the text files I am interested in)).

    /Not sure if that helps with debugging. It would be great if you could get it to render the Asian characters.
      My Computer


  10. Posts : 1,680
    X
       #10

    So difficult with native Windows tools.
    So easy with Linux:
    Code:
    du | grep "^0"
    If you install the Windows Subsystem for Linux (WSL) you get all Linux capabilities whilst keeping Windows intact.
    Or install Cygwin, with similar capabitilites.
    Both are free.
      My Computer


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 13:58.
Find Us




Windows 10 Forums