Is there a way to delete all empty sub-directories below a given directory from a batch file?
Or is it possible to recursively copy a directory, but excluding any empty directories?
Is there a way to delete all empty sub-directories below a given directory from a batch file?
Or is it possible to recursively copy a directory, but excluding any empty directories?
To copy ignoring empty dirs you can use one of:
robocopy c:\source\ c:\dest\ * /s
xcopy c:\source c:\dest\*.* /s
xcopy's /s will ignore blank folder when copying
xcopy * path\to\newfolder /s /q
@echo off
setlocal ENABLEEXTENSIONS
call :rmemptydirs "%~1"
goto:EOF
:rmemptydirs
FOR /D %%A IN ("%~1\*") DO (
REM recurse into subfolders first...
call :rmemptydirs "%%~fA"
)
RD "%~f1" >nul 2>&1
goto:EOF
Call with: rmemptydirs.cmd "c:\root dir to delete empty folders in"