Article View: comp.os.msdos.misc
Article #3845Re: batch file to delete files of certain size?
From: John Savage
Date: Mon, 15 Apr 1996 00:00
Date: Mon, 15 Apr 1996 00:00
85 lines
4403 bytes
4403 bytes
kwh@dgsys.com (Kirshner) wrote:
>michael lepore (lepore89@matrix.newpaltz.edu) wrote:
>> Can a batch file do something like this ... if there are any files in
>> the current directory that are 150 bytes in size then delete them ...
>> or even give it a name: if file xxx is that size then delete it ...
>
>:: DELSIZE.BAT - Deletes files of specified size in current directory.
>::
>:: Requires DOS utility 'LOADFIX.COM' to be copied to "ENTER.COM'
>:: in a directory on the PATH (or the current directory).
>::
>:: Sizes greater than 999 bytes need to be comma delimited
>:: (i.e. 1,024 - 2,345,000 - etc)
>::
>:: Tom Lavedas (kwh@dgs.dgsys.com)
>::
> @echo %dbgd% off
> if [%1]==[] for %%v in (echo goto:End) do %%v Syntax: %0 Size
> set {s}=%1
> :Loop
> if not [%2]==[] for %%v in (set shift goto:Loop) do %%v {s}=%{s}%,%2
>> %temp%.\ne}.bat dir | sort /r | date | find " %{s}% "
> if errorlevel 1 for %%v in (echo goto:End) do %%v No %{s}% byte files.
>> %temp%.\new.bat echo @echo off
>>>%temp%.\new.bat echo File %%3.%%4 deleted.
>>>%temp%.\new.bat echo del %%3.%%4
> call %temp%.\ne}
> del %temp%.\ne?.bat
> :End
> set {s}=
>
>I haven't time to explain all its workings, but you need to know that it
>uses the DOS LOADFIX.COM utility to process the list of files matching
>the size requirement. Make a copy of this program named ENTER.COM and
>store it in a directory on the PATH (such as DOS). I learned this trick
>from Neil Rubenking in the User-to-User column in PC Magazine (US) last
>year.
>
>Tom Lavedas - Contributing Editor
That's an interesting coupling of sort /r & date; just as well the
application didn't call for an unsorted listing! And you have an
interesting use for loadfix, too. Apparently your DOS is set up to
show commas in the file size, but I've deleted that portion simply
because there are no commas in sight on my DOS. Anyway, ...
The program shown above is safe enough to use in directories where
all the filenames have filename extensions, but it *could* happen to
delete the wrong file if there are some with no filename extension.
Tom has done the hard groundwork, so I'll add a few refinements to
make it into a batch file whose operation is more watertight. (But
it's still not totally safe where there are filenames containing any
leading/included/trailing \032 spaces in the basename or extension.)
The above test for "No files to delete" is not reliable because it
makes no distinction between a numeric filename, extension, or size,
so I've just left it out altogether.
DELSIZE.BAT
-----------
@echo off
if [%1]==[] for %%v in (echo goto:End) do %%v Syntax: %0 Size
> %temp%ne}.bat dir | sort /r | date | find " %1 "
> %temp%new.bat echo @echo off
copy c:\dos\loadfix.com %temp%enter.com >nul
echo if %%5==%1 if not %%4==file(s) echo File %%3.%%4 deleted >>%temp%new.bat
echo if %%5==%1 if not %%4==file(s) del %%3.%%4 >>%temp%new.bat
echo if "%%7"=="" if %%4==%1 if exist %%3 echo File %%3 deleted >>%temp%new.bat
echo if "%%7"=="" if %%4==%1 if exist %%3 del %%3 >>%temp%new.bat
call %temp%ne}
del %temp%ne?.bat
del %temp%enter.com
:End
:: when %%7 is a null, then the filename has no extension
:: %%4==file(s) eliminates attempts to delete a second file named, e.g.,
:: 35.FIL, caused by the totals line of a directory listing
:: if exist %%3 prevents attempts to delete any of the empty temporary
:: DOS-pipe files when targetting files of size 0 bytes
--
John Savage koala@sydney.dialix.com.au
Technical Details
Message-ID:
<4ktcr4$41q@nhj.nlc.net.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<4jhq8r$qv1@motss.newpaltz.edu> <4kb2bh$7mo@news.dgsys.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10d683,1b61cb609540aee0 X-Google-Attributes: gid10d683,public X-Google-Thread: 104805,1b61cb609540aee0 X-Google-Attributes: gid104805,public X-Google-Thread: f71eb,50bda013f7eab191 X-Google-Attributes: gidf71eb,public From: John Savage <koala@sydney.dialix.com.au> Subject: Re: batch file to delete files of certain size? Date: 1996/04/15 Message-ID: <4ktcr4$41q@nhj.nlc.net.au> X-Deja-AN: 147580618 distribution: world sender: js2000@nlc.net.au references: <4jhq8r$qv1@motss.newpaltz.edu> <4kb2bh$7mo@news.dgsys.com> content-type: TEXT/PLAIN; charset=US-ASCII organization: Gumleaf Smoke Signals Telegraph Co. mime-version: 1.0 newsgroups: comp.os.msdos.misc,alt.msdos.batch,aus.computers.ibm-pc