cleaner.bat -- critique and recommendations

  • Thread starter Thread starter aurgathor
  • Start date Start date
A

aurgathor

I have a dual boot PC (DOS & W2K -- W98 wouldn't run)
and I wrote the below .bat file to get rid of the crap that seems
to accumulate over time. The very first run yielded over 250 meg
on my W2K boot drive (FAT32), but I'm still looking for some
ideas to enhance it, either add some more deletable locations,
or just make the program a little smarter. This program meant
to be run from DOS on a FAT32 drive containing the W2K install.

TIA

echo Cleaning crap...

cd\
cd Docume~1
cd Admini~1
cd Locals~1
cd Temp
echo y | del *.*
deltree /y *.*
cd ..
cd Tempor~1
echo y | del *.*
cd Content.IE5
deltree /Y *.*

cd\
cd Docume~1
cd User_1
cd Locals~1
cd Temp
echo y | del *.*
deltree /y *.*
cd ..
cd Tempor~1
echo y | del *.*
cd Content.IE5
deltree /Y *.*


cd\
cd Docume~1
cd Defaul~1
cd Locals~1
cd Temp
echo y | del *.*
deltree /y *.*
cd ..
cd Tempor~1
echo y | del *.*
cd Content.IE5
deltree /Y *.*


cd\
cd Winnt
cd Temp
echo y | del *.*
deltree /y *.*

echo done.
 
See below

aurgathor said:
I have a dual boot PC (DOS & W2K -- W98 wouldn't run)
and I wrote the below .bat file to get rid of the crap that seems
to accumulate over time. The very first run yielded over 250 meg
on my W2K boot drive (FAT32), but I'm still looking for some
ideas to enhance it, either add some more deletable locations,
or just make the program a little smarter. This program meant
to be run from DOS on a FAT32 drive containing the W2K install.

TIA

Your batch file is a bit chatty, which makes it harder
to see what's going on. You also need to distinguish
between Win2000 and DOS.
echo Cleaning crap...

cd\
cd Docume~1
cd Admini~1
cd Locals~1
cd Temp

*** Combine these file lines into a single line:
cd /d c:\Docume~1\Admini~1\Locals~1\temp
echo y | del *.*
deltree /y *.*

*** Deltree is not a Win2000 command. Use rd /s instead:
*** ver | find /i "Windows 2000"
*** if not ErrorlLevel 1 rd /s /q . . .
*** if ErrorLevel 1 deltree /y . . .
 
aurgathor said:
I have a dual boot PC (DOS & W2K -- W98 wouldn't run)
and I wrote the below .bat file to get rid of the crap that seems
to accumulate over time. The very first run yielded over 250 meg
on my W2K boot drive (FAT32), but I'm still looking for some
ideas to enhance it, either add some more deletable locations,
or just make the program a little smarter. This program meant
to be run from DOS on a FAT32 drive containing the W2K install.

TIA

echo Cleaning crap...
<batch code snipped>

Nooooo! Never use *.* to delete from current folder. No good can come from
deleting the wrong files by accident. Always include a path to specifically
identify the directory you want to delete from. Also, it is not necessary to
use both deltree and DEL. Your entire batch can be reduced to the following
7 lines.

deltree /y \Docume~1\Admini~1\Locals~1\Temp\*.*
deltree /y \Docume~1\Admini~1\Locals~1\Tempor~1\*.*
deltree /y \Docume~1\User_1\Locals~1\Temp\*.*
deltree /y \Docume~1\User_1\Locals~1\Tempor~1\*.*
deltree /y \Docume~1\Defaul~1\Locals~1\Temp\*.*
deltree /y \Docume~1\Defaul~1\Locals~1\Tempor~1\*.*
deltree /y \Winnt\Temp\*.*

Personally, I would leave off the *.*, but that is just me.
 
Doesn't Win2K's "Disk Cleanup" tool do all this
(and more). Or am I missing something?
 
Todd said:
<batch code snipped>
Nooooo! Never use *.* to delete from current folder. No good can come from
deleting the wrong files by accident. Always include a path to specifically
identify the directory you want to delete from.

*** Good advice.

Also, it is not necessary to use both deltree and DEL. Your entire
batch can be reduced to the following 7 lines.

deltree /y \Docume~1\Admini~1\Locals~1\Temp\*.*
deltree /y \Docume~1\Admini~1\Locals~1\Tempor~1\*.*
deltree /y \Docume~1\User_1\Locals~1\Temp\*.*
deltree /y \Docume~1\User_1\Locals~1\Tempor~1\*.*
deltree /y \Docume~1\Defaul~1\Locals~1\Temp\*.*
deltree /y \Docume~1\Defaul~1\Locals~1\Tempor~1\*.*
deltree /y \Winnt\Temp\*.*

*** It could be reduced to one line with a FOR-IN-DO.

Personally, I would leave off the *.*, but that is just me.

*** I too, like to add the " *.* ". I find it more readable when I am
perusing batch file code in that when I see it, I know it means all
files, possibly excepting hidden & system ones.

Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
 
Richard Bonner said:
*** It could be reduced to one line with a FOR-IN-DO.

By my count, that would be a 246 character FOR-IN-DO command. Although the
command line of Win98 can optionaly be expanded to 255 characters, let's
remember the general focus of this group is for DOS users where the command
line length is only 128 characters.
 
By my count, that would be a 246 character FOR-IN-DO command. Although the
command line of Win98 can optionaly be expanded to 255 characters, let's
remember the general focus of this group is for DOS users where the command
line length is only 128 characters.

*** True, but newer DOS versions, 4DOS, and after-market extenders have
been around for quite some time. They all support longer command-line
lengths.

Regardless, point taken.

Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
 
Richard said:
Todd Vargo wrote:

So how about this two line version ?

for %%x in (Admini~1 User_1 Defaul~1) do for %%y in (Temp Tempor~1) do deltree /y C:\Docume~1\%%x\Locals~1\%%y\*.*
deltree /y C:\Winnt\Temp\*.*

Compound "for" statements have their occasional uses ;-)
 
Richard Bonner wrote:
^
*** True, but newer DOS versions, 4DOS, and after-market extenders
have been around for quite some time. They all support longer
command-line lengths.

With 4DOS you can use an include list (external file, e.g. dirfile.dat)
with many commands, which would make maintenance of the directories
concerned easier (imho). Something like

del /s /e /x /y @dirfile.dat *.*

(The *.* could be in dirfile.dat or missing totally).
 
.... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
So how about this two line version ?

for %%x in (Admini~1 User_1 Defaul~1) do for %%y in (Temp Tempor~1) do
deltree /y C:\Docume~1\%%x\Locals~1\%%y\*.*
deltree /y C:\Winnt\Temp\*.*

Compound "for" statements have their occasional uses ;-)

Unfortunatly, DOS (command.com) does not allow it.
 
Todd said:
... ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



deltree /y C:\Docume~1\%%x\Locals~1\%%y\*.*



Unfortunatly, DOS (command.com) does not allow it.

But the OP cross-posted to a W2K newsgroup, so he presumably
would be using W2K's cmd.exe instead of pissing around with
command.com.
 
Rob Stow said:
But the OP cross-posted to a W2K newsgroup, so he presumably
would be using W2K's cmd.exe instead of pissing around with
command.com.

Does W2K have a DELTREE command?
 
Todd said:
Does W2K have a DELTREE command?

Its up to the user. W2K does not have a native DelTree, but you can copy
over the .exe file from a Win9x system. There are also third party versions
of DelTree.
 
Rob said:
Its up to the user. W2K does not have a native DelTree, but you can copy
over the .exe file from a Win9x system. There are also third party versions
of DelTree.

Do you have experience in using Win9x's DELTREE.EXE under W2K or XP ?
 
Larry__Weiss said:
Do you have experience in using Win9x's DELTREE.EXE under W2K or XP ?

With W2K, yes. Works fine - but I have run into permissions
issues when using it as a non-admin.
 
Rob said:
With W2K, yes. Works fine - but I have run into permissions
issues when using it as a non-admin.

Forgot to mention that I haven't seen a need to use DelTree for a
*long* time. The commands built into cmd.exe, such as "rd /s /q"
does the job just fine for me.

The only time I use DelTree any more is when I'm working for some
idiot who insists that I use it.
 
Rob said:
Forgot to mention that I haven't seen a need to use DelTree for a
*long* time. The commands built into cmd.exe, such as "rd /s /q"
does the job just fine for me.

The only time I use DelTree any more is when I'm working for some
idiot who insists that I use it.

Would you have encountered the same non-admin permissions issues with "rd /s /q" ?
 
Rob Stow said:
With W2K, yes. Works fine - but I have run into permissions
issues when using it as a non-admin.

Interesting. To "copy" deltree from Win9x to another OS, that would mean
Microsoft removed version checking. That is so unlike Microsoft.
 
Back
Top