Windows 7 - Script to delete files on shutdown

Asked By fieseler on 11-Nov-08 04:48 PM
I want to have windows to automatically delete all files in my temp
folder on shutdown except one. I know how to use gpedit to run scripts
on shutdown. I need someone make the script for me to remove said files
if its possible?

btw i moved my temp folder to 'C:\temporary Files' & the one file i
dont want it to delete is 'C:\temporary Files\Darren.bmp'


--
fieseler

Pirating MS Vista is a crime & a waste of 97 hours looking for a crack
that doesnt virus your pc!




Pegasus \(MVP\) replied on 11-Nov-08 06:06 PM
The simplest method would consist of putting these two lines into your
shutdown batch file:

@echo off
for /F "delims=" %%a in ('dir /b /a-d "c:\Temporary Files" ^| find /i /v

Remove the word "echo" in Line 2 to activate the batch file. BTW - I don't
think it's a good idea to keep files in the temp directory if you want to
keep them. Without this restriction the command would be much simpler:
@echo off
del /q "c:\Temporary Files"
fieseler replied on 12-Nov-08 04:30 AM
I got the this one to work

@echo off
del /q "c:\Temporary Files"

but the other one below wont delete files at all for some reason. I did
remember to remove the echo in the last line also.

@echo off
for /F "delims=" %%a in ('dir /b /a-d "c:\Temporary Files" ^| find /i
/v

Plus is there any way to get it to delete folders as well? I have a few
folders in there often left by one of my sidebar gadgets. I want these
to be deleted also because the gadget just creates new ones every time
it runs anyway.


--
fieseler

Pirating MS Vista is a crime & a waste of 97 hours looking for a crack
that doesnt virus your pc!
Pegasus \(MVP\) replied on 12-Nov-08 05:29 AM
It looks as if your newsreader broke up the second line. Remember - the
solution I suggested consists of exactly two lines. The second line is a
very long line.

To delete folders:

@echo off
for /F %%a in ('dir /b /ad "c:\Temporary Files"') do echo rd /s /q "%%a"

Again you need to follow this sequence:
1. Create the batch file with the two lines above.
2. Run it from a Command Prompt (not from the Run box!).
3. Satisfy yourself that it would do the right thing.
4. Remove the word "echo" in the second line.

Performing Step 4 while ignoring Step 3 is dangerous!
fieseler replied on 12-Nov-08 11:06 AM
hi,
again strangely i couldnt get it to work for some reason. I did a
google search & came up with:

del %TEMP%\*.* /s /f /q
for /d %%x in (%TEMP%\*) DO rmdir /s /q "%%x"

but again, it deletes 'Darren.bmp' which idont want it to do. Btw this
is my user account picture for some reason in the temp folder, if i
delete it & log off, it takes a few seconds to create it before i or
someone else can log in again which can get annoying.


--
fieseler

Pirating MS Vista is a crime & a waste of 97 hours looking for a crack
that doesnt virus your pc!
Pegasus \(MVP\) replied on 12-Nov-08 12:41 PM
Let's have a look at the screen output you see when you execute the very
first script I gave you, with the "echo" word in place in the second line.
fieseler replied on 13-Nov-08 05:59 AM
i got it to work last night, but it only runs when its in my temp folder
itself, so ends up deleting itself


--
fieseler

Pirating MS Vista is a crime & a waste of 97 hours looking for a crack
that doesnt virus your pc!
Darre replied on 14-Nov-08 06:06 AM
did you manage to get this figured out? I would also like to know how to get
it to work as my temp folder is always overflowing with garbage.
Pegasus \(MVP\) replied on 14-Nov-08 07:28 AM
Did you try this simple command?

del /s /q "%temp%\*.*"
BigDaddyJim replied on 15-Nov-08 06:37 PM
o

Try this.  It seems to work fine for me...

for /F %%s in ('dir /b') do del /f /s /q "%docs%\%%s\local settings
\temp\*.*" & del /f /s /q "%docs%\%%s\Local Settings\Temporary
Internet Files\*.*"
for /D %%r in (*) do attrib -H -S "%docs%\%%r\local settings\temp" /S /
D & rd /s /q "%docs%\%%r\local settings\temp" & attrib -H -S /S /D
\%%r\Local Settings\Temporary Internet Files"