Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
If the following script finds the deepest subfolders of the directory:
@echo off
setlocal enabledelayedexpansion
set /a N=0
for /r "C:\MainFld" %%a in (.) do ( dir /ad /b "%%a" | find /v "" >nul
if errorlevel 1 (
set /a N+=1
ren "%%a" Fld!N!
)
)How could I modify this to find every subfolder in the directory that have one or more files... excluding the subfolders that have no files...
For example, given this path:
C:\mainFld\Folder\SubFolder\SubSubFolderAnd say there were stray files under Folder and SubSubFolder, but not SubFolder... (say the only thing under SubFolder was SubSubfolder and no files)... how could I exclude SubFolder from the above script.
Thank you for your time and continued help!

I don't follow your script, but you can find which folders are empty [no files].
dir /b/a-d foldname
if errorlevel 1 echo it's empty
=====================================
If at first you don't succeed, you're about average.M2

Thank-you M2, this works...
But how would I do this for every folder in a directory?
I tried
setlocal enabledelayedexpansion
for /f "tokens=* delims= " %%a in ('dir /b/a-d "C:\MainFolder"') do (
if errorlevel 1 echo %%a it's empty
)but couldn't get this (or other attempts) to work...
Thank you for your help.

@echo off
setLocal EnableDelayedExpansionset /p D=start where?
pushd !D!for /f "tokens=* delims= " %%a in ('dir/b/s/ad') do (
dir/b/a-d "%%a" > nul 2> nul
if errorlevel 1 echo %%a is empty
)
=====================================
If at first you don't succeed, you're about average.M2

![]() |
batch move files log help
|
Batch Extract Text File &...
|

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |