🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: alt.msdos.programmer
Article #374

Re: Need DOS batch help!

#374
From: Nick FitzGerald, CSC, Uni. of Ca...
Date: Thu, 13 Aug 1992 01:00
57 lines
2854 bytes
In article <1992Aug12.141526.25165@athena.mit.edu>, chanh@athena.mit.edu
(Chanh N. Vuong) writes:
> In article <92225.09262732BFPQ3@CMUVM.CSV.CMICH.EDU> Nathan Owen
<32BFPQ3@CMUVM.CSV.CMICH.EDU> writes:
>>I having a problem writing a batch file.  I need a batch file which will go
>>to a c:\Temp directory and delete every file in the directory except for
>>a file named gest.bat.  The batch must be written in such a way they the
>>user will not get a message asking Yes/No (Y/N) in response to deleting
>>the files , which limits your use of wildcard deletes like del *.*.
> 
> DEL_TEMP.BAT:
> @echo off
> c:
> cd \
> cd temp
> md tmp
> copy gest.bat tmp
> for %%a in (*.*) do del %%a
> copy c:\temp\tmp\gest.bat .
> del c:\temp\tmp\gest.bat
> rd tmp
> cd \

I'd add a bit of error checking to make sure the tmp dir is actually
created.  e.g.

if not exist tmp\nul goto :md_failed

(With some versions of DOS you may have to put a colon after the device
name - "nul:" - I'm getting a bit hazy on this.)

(NOTE:  The "if exist" test above won't work on at least some NetWare
drives.  Regardless of how ficticious a directory name you give, you
will be told that the file exists.  You also can't use this type of test
on a NetWare drive to tell if you have read or filescan access to a dir
- if you test for the existence of any of the DOS device psuedo files
regardless of the directory structure and your access rights, "if exist"
returns true.  I've never seen this "feature" mentioned anywhere before
- surely I'm not the first to discover it!)

Also check that gest.bat copied OK before deleting all the files in the
\temp dir and again before deleting the version in tmp.  There are other
checks you could make as well - depends on how bomb-proof you want to
make it and on who will be using it.

Nathan's claim that you won't be able to use "del *.*" is incorrect. 
Try the following instead of Chanh Vuong's elegant "for..." line:

echo y >y.dat
del *.* <y.dat >nul

From some experience I'd expect the above to execute faster if more than
3 or 4 files are being deleted.

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
 Nick FitzGerald, PC Applications Consultant, CSC, Uni of Canterbury, N.Z.
 n.fitzgerald@csc.canterbury.ac.nz    (64)(3)  642-337 Voice,  642-332 FAX
Technical Details
Message-ID: <1992Aug13.130054.312@csc.canterbury.ac.nz>
Path: arc1-ca.pugleaf.net!sparky!uunet!comp.vuw.ac.nz!waikato.ac.nz!canterbury.ac.nz!cctr132
References: <92225.09262732BFPQ3@CMUVM.CSV.CMICH.EDU> <1992Aug12.141526.25165@athena.mit.edu>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!comp.vuw.ac.nz!waikato.ac.nz!canterbury.ac.nz!cctr132
Newsgroups: alt.msdos.programmer
Subject: Re: Need DOS batch help!
Message-ID: <1992Aug13.130054.312@csc.canterbury.ac.nz>
From: cctr132@csc.canterbury.ac.nz (Nick FitzGerald, CSC, Uni. of Canterbury, NZ)
Date: 13 Aug 92 13:00:54 +1200
References: <92225.09262732BFPQ3@CMUVM.CSV.CMICH.EDU> <1992Aug12.141526.25165@athena.mit.edu>
Organization: University of Canterbury, Christchurch, New Zealand
Lines: 57