need batch file for check folder and subfolde

October 2, 2011 at 02:50:09
Specs: Windows xp
need batch file for windows xp to check folder and subfolder size and based on the size folder root it will deletes subfolder and files.

example : there is a folder on drive d: called (test) and it contains files and subfolders
i need batch to check the size of test folder and if the size equal 180 mb delete all the content of the test folder .

P.S i need keep the root folder (test) do not delete


See More: need batch file for check folder and subfolde

Report •

#1
October 7, 2011 at 07:52:56
@echo off
setlocal
for /f "tokens=3" %%a in ('dir test /s ^| find "File(s)"') do set size=%%a
if "%size%"=="180,000,000" del test /s /q

Report •

#2
October 7, 2011 at 09:12:31
if "%size%"=="180,000,000" del test /s /q
One megabyte is 1,048,576 bytes, not 1,000,000. Also, you're doing text comparison and expecting it to give identical results as a numerical comparison. It shouldn't be an issue as long as you're doing straight equality, but an equality test is ineffectual for the desired purpose.

How To Ask Questions The Smart Way


Report •

#3
October 7, 2011 at 12:18:43
@echo off
setlocal
for /f "tokens=3" %%a in ('dir test /s ^| find "File(s)"') do set size=%%a
if /i %size:,=% equ 188743680 del test /s /q

Happy? =P

OP, you said if the size "equals" 180mb. That's pretty exact. change "equ" in the above to "gtr" if you want to check if it's greater than 180mb.

And Razor, I know the issues, but I figured the OP could modify it for his needs.


Report •

Related Solutions

#4
October 7, 2011 at 13:21:19
lavascript: Happy? =P
Never.

How To Ask Questions The Smart Way


Report •

Ask Question