-1

I have a batch file that is supposed to identify the smallest directory and delete all other direcotires only leaving the smallest one.

The identification works properly, but the removal of the other, larger folders doesn't work. Below is what I have now. What needs to be changed?

@echo off
setlocal EnableDelayedExpansion

rem Get size of all folders
set smallestSize=9999999999
for /D %%a in (*) do (
   set size=0
   for %%b in (%%a\*.*) do set /A size+=%%~Zb
   if !size! lss !smallestSize! (
      set smallestSize=!size!
      set smallestName=%%a
   )
)

echo Deleted folder: "%smallestName%"
pause

rem Delete all folders, except the smallest one.
for /D %%a in (*) do (
   if "%%a" neq "%smallestName%" rmdir /S /Q "%%a"
Ken White
  • 123,280
  • 14
  • 225
  • 444
Manny90
  • 9
  • 3
  • You should follow your doubts in the [original question](http://stackoverflow.com/questions/26689398/batch-file-commands-to-keep-smallest-directory-and-delete-all-others). If the above is the program you run, then you missed the last line (with a right parentheses). – Aacini Nov 02 '14 at 04:28

1 Answers1

0

Could be a simple typo - there's a missing close-parenthesis for the final for/do

Magoo
  • 77,302
  • 8
  • 62
  • 84