Small Script wanted

  • Thread starter Thread starter Harry Sampson
  • Start date Start date
H

Harry Sampson

Hi,

I would like to be able to place a file or script on my desktop that when
activated would clean out my temp directory located here:

C:\Documents and Settings\HS\Local Settings\Temp

If there are files that are currently in use when the script is activated,
the script should skip over those "busy" files and continue deleting all
other files and subdirectories and their contents.

I am hoping that this is a small request of only a couple lines.

Thank you.

HS
 
With Notepad, create & save a one-line .bat (batch) file containing
erase C:\Documents and Settings\HS\Local Settings\Temp\*.*
and put a shortcut to it on your desktop.

To create the shortcut, rightclick on the desktop, select New, and
follow your nose down the Shortcut path.

Start/Help/Reference contains the list, descriptions, and syntax of all
W2k's available MSDOS commands, of which erase is one. A batch file is
an executable within the W2k DOS emulator (the "Command Prompt").
 
Dan Seur wrote...
With Notepad, create & save a one-line .bat (batch) file containing
erase C:\Documents and Settings\HS\Local Settings\Temp\*.*
and put a shortcut to it on your desktop.

To create the shortcut, rightclick on the desktop, select New, and
follow your nose down the Shortcut path.

Start/Help/Reference contains the list, descriptions, and syntax of all
W2k's available MSDOS commands, of which erase is one. A batch file is
an executable within the W2k DOS emulator (the "Command Prompt").

Dan,

I created a file called CleanTemp.bat. The file contains:

erase C:\Documents and Settings\HS\Local Settings\Temp\*.*

I stored the file on both my desktop, and on my C drive with a shortcut to
it.

I tried both instances of the file (desktop and C drive), and neither one
cleaned out the temp directory.

My temp directory is reasonably clean now, so to ensure that all files were
not in use, I copied some "junk" files from my personal "junk bucket" into
this temp directory. The batch file did not erase the files as hoped.

When I engage the the batch file, I get a quick "blip" and then nothing. I
thought the blip was the files being erased. But that is obviously not the
case.

With regard to the help stuff, I have all the "Dell" support junk, so it
simply says to go to the C prompt and type help or something. There wasn't
a comprehensive list of commands.

HS
 
You'd use the Notepad "save as", and give it any "name.bat" - and
remember where you put it, so when you create the shortcut you can
easily navigate (using browse) to it, and click OK.

It must have the .bat extension; temperase.bat would be an example.

The filename part, before the dot, doesn't matter. The OS looks at the
..bat, which says "I'm an executable of the batch type", and executes
whatever's in the file.

A batch program is DOS-type code that, in W2k, will be executed by W2k's
DOS simulation software. If what's in the file is malformed or otherwise
not executable DOS commands, the system will simply return an error and
you can use Notepad to fix the error.

Note that it's a good idea, over the long haul, to give files you create
names that are meaningful to you. Then later you can more easily find
them when you need to.
 
I have a VBScript that does that, see the vbspage link in my signature. I recommend you put a shortcut in your Startup folder and not run it directly, to avoid deleted files that are needed for a function that was deferred until reboot (installing a new program, for example). This script has some advantages over using a batch file, such as determining the actual folder for the currently logged in user instead of having to hardcode it in a batch file, and it will automatically skip over any locked files.

--

Bill James
Microsoft MVP - Shell/User

Windows VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/
 
erase C:\Documents and Settings\HS\Local Settings\Temp\*.*

try

cmd %comspec% /k erase %temp% /f /s /q

Where /f forces deleting of read only files, /s cleans out
subdirectories, /k will keep the CMD window open so you can see if the
operation was successful, replace it with /c when you are happy and /q
does everything quietly, so it may be wise to make sure that
everything in the %temp% is everything you want rid of.

HTH
 
Bill James wrote...
I have a VBScript that does that, see the vbspage link in my signature. I
recommend you put a shortcut in your Startup folder and not run it directly,
to avoid deleted files that are needed for a function that was deferred
until reboot (installing a new program, for example). This script has some
advantages over using a batch file, such as determining the actual folder
for the currently logged in user instead of having to hardcode it in a batch
file, and it will automatically skip over any locked files.

--

Bill James
Microsoft MVP - Shell/User

Windows VBScript Utilities » www.billsway.com/vbspage/
Windows Tweaks & Tips » www.billsway.com/notes_public/

-----------------

Bill,

Thank you. That looks like it should serve my needs very well.

HS
 
Andy Brown wrote
cmd %comspec% /k erase %temp% /f /s /q

Where /f forces deleting of read only files, /s cleans out
subdirectories, /k will keep the CMD window open so you can see if the
operation was successful, replace it with /c when you are happy and /q
does everything quietly, so it may be wise to make sure that
everything in the %temp% is everything you want rid of.

HTH

Andy,

That's great. Can you modify that slightly to not only clean out the
subdirectories, but also remove the subdirectories?

In my tests, the subs are cleaned out but they do remain behind.

Thank you.

HS
 
That's great. Can you modify that slightly to not only clean out the
subdirectories, but also remove the subdirectories?

Hi Harry please try

cmd %comspec% /c erase %temp% /f /s /q^|rd /s %temp% /q
md %temp% >nul

In a batch file it should delete all temp files then remove all temp
folders, then recreate them for you. Please copy and paste the above
lines as they are posted into Notepad or similar text editor, they
worked for me, but as sods law indicates they may not for you. :)
In my tests, the subs are cleaned out but they do remain behind.

Thank you.

This one should sort it for you, hope it helps.
 
Andy Brown wrote....
Hi Harry please try

cmd %comspec% /c erase %temp% /f /s /q^|rd /s %temp% /q
md %temp% >nul

In a batch file it should delete all temp files then remove all temp
folders, then recreate them for you. Please copy and paste the above
lines as they are posted into Notepad or similar text editor, they
worked for me, but as sods law indicates they may not for you. :)


This one should sort it for you, hope it helps.

Andy,

Thank you very much for your assistance. I haven't tried it yet, but I
assume that it works as advertised. If not, I'll be back.

HS
 
Back
Top