Solved Create .bat file to check file size & delete old file if . .

October 9, 2012 at 15:02:28
Specs: Windows 7
Can anyone help me create a .BAT file which checks the size of 2 files & deletes the smallest sized file ?

If anyone can help let's call the file - 'file.exe'.

BTW the script will be run on server 2003


See More: Create .bat file to check file size & delete old file if . .

Report •

#1
October 9, 2012 at 19:03:03
I'll try (usage: smalldel file1 file2):

::===== begin script smalldel.bat

@echo off & setlocal enabledelayedexpansion
set ii=aa
for %%a in (%1 %2) do (
if %%~za lss !ii! (
set ii=%%~za
set fn=%%a
)
)
echo del %fn%
::====== end

might also be done with sort...


Report •

#2
October 10, 2012 at 03:31:49
:: ===== script starts here ===============
::
:: DELsmall.bat 2012-10-10 17:26:35.71
@echo off & setLocal enableDELAYedeXpansioN

for /f "tokens=* delims= " %%a in ('dir/b/os this that') do (
echo del %%a
goto :eof
)
::====== script ends here =================


====================================
Life is too important to be taken seriously.

M2


Report •

#3
October 11, 2012 at 07:42:50
✔ Best Answer
Mechanix2Go your awesome,
I have seen your posts starting from years ago & you are very helpfull, your a credit to this forum, thank you for the solution, it worked.

Report •

Related Solutions

#4
October 11, 2012 at 07:44:23
Also thank you nbrane,

Yours worked (tweaking it a little), its just Mechanix2Go's solution is more simple to use,
Thank you again though.


Report •

#5
October 11, 2012 at 19:30:54
Yeah, I like his version much better. my brain was blocked from "dir /o:s" for some reason.

Report •

#6
October 12, 2012 at 00:43:07
Thanks for the kind words.

FWIW,you could del the smallEST of a bunch.

like dir/b/o-d *.txt


====================================
Life is too important to be taken seriously.

M2


Report •

Ask Question