Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Script to delete files on shutdown

Reply
 
Old 11-11-2008   #1 (permalink)


Vista Ultimate SP1 x64
 
 

Script to delete files on shutdown

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'

My System SpecsSystem Spec
Old 11-11-2008   #2 (permalink)
Pegasus \(MVP\)


 
 

Re: Script to delete files on shutdown


"fieseler" <guest@xxxxxx-email.com> wrote in message
news:fcf970a6200385c5dab6b112c63e66a1@xxxxxx-gateway.com...
Quote:

>
> 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'
>
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
"Darren.bmp"') do echo del "%%a

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"


My System SpecsSystem Spec
Old 11-12-2008   #3 (permalink)


Vista Ultimate SP1 x64
 
 

Re: Script to delete files on shutdown

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
"Darren.bmp"') do del "%%a

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.
My System SpecsSystem Spec
Old 11-12-2008   #4 (permalink)
Pegasus \(MVP\)


 
 

Re: Script to delete files on shutdown


"fieseler" <guest@xxxxxx-email.com> wrote in message
news:276f42455ef2b6f05cf64737d3ae27b7@xxxxxx-gateway.com...
Quote:

>
> 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
> "Darren.bmp"') do del "%%a
>
> 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.
>
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!


My System SpecsSystem Spec
Old 11-12-2008   #5 (permalink)


Vista Ultimate SP1 x64
 
 

Re: Script to delete files on shutdown

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.
My System SpecsSystem Spec
Old 11-12-2008   #6 (permalink)
Pegasus \(MVP\)


 
 

Re: Script to delete files on shutdown


"fieseler" <guest@xxxxxx-email.com> wrote in message
news:53eee35d8f1e2fac95061ce2df030d38@xxxxxx-gateway.com...
Quote:

>
> 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
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.


My System SpecsSystem Spec
Old 11-13-2008   #7 (permalink)


Vista Ultimate SP1 x64
 
 

Re: Script to delete files on shutdown

i got it to work last night, but it only runs when its in my temp folder itself, so ends up deleting itself.

both versions for cleaning the temp folders & files work fine apart from said problem.

Last edited by fieseler; 11-14-2008 at 05:56 AM..
My System SpecsSystem Spec
Old 11-14-2008   #8 (permalink)
Darren


 
 

Re: Script to delete files on shutdown

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.

"fieseler" wrote:
Quote:

>
> 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!
>
My System SpecsSystem Spec
Old 11-14-2008   #9 (permalink)
Pegasus \(MVP\)


 
 

Re: Script to delete files on shutdown


"Darren" <Darren@xxxxxx> wrote in message
news:49C5DDCF-53F7-4E6D-8C85-11BE3EC962FC@xxxxxx
Quote:

> 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.
>
Did you try this simple command?

del /s /q "%temp%\*.*"


My System SpecsSystem Spec
Old 11-14-2008   #10 (permalink)
BigDaddyJim


 
 

Re: Script to delete files on shutdown

On Nov 14, 6:28*am, "Pegasus \(MVP\)" <I....@xxxxxx> wrote:
Quote:

> "Darren" <Dar...@xxxxxx> wrote in message
>
> news:49C5DDCF-53F7-4E6D-8C85-11BE3EC962FC@xxxxxx
>
Quote:

> > 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.
>
> Did you try this simple command?
>
> del /s /q "%temp%\*.*"
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
"%docs%\%%r\Local Settings\Temporary Internet Files" & rd /s /q "%docs%
\%%r\Local Settings\Temporary Internet Files"
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
delete temp files via script - can B added 2 startup VB Script
Script to delete folder with specific name and files VB Script
Shutdown and startup Hyper-V Virtual Machine via script Virtual Server
RE: Shutdown Guest OS Script Problem Virtual Server
Group Policy - I need to write a script to run on shutdown Vista security


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46