How to delete files in Windows\Temp? 
Author Message
 How to delete files in Windows\Temp?

Dear all, I'm trying to clean up the Windows\Temp directory but as you know
there are files which can't be accessed because they're in use by Windows.
So if I try Kill, I would only get Access runtime error. So instead I
specify the file types to delete, but then there are files that have no
extension. Is there a way to specify "anything but *.tmp" in VB? Or better,
"anything that's not in use by Windows"? The crude code I'm using at the
moment
is:

    File2.Pattern = "*.doc;*.htm;*.html;*.exe;*.txt;*.zip;*.pdf"
    File2.Path = WinTmpDir
    For i = 0 To File2.ListCount - 1
        Kill (File2.Path & "\" & File2.List(i))
    Next

Thanks,
            Jules

***24 hours in a day...24 beers in a case...coincidence?***



Wed, 15 Aug 2001 03:00:00 GMT  
 How to delete files in Windows\Temp?
Set the pattern to "*.*"
Just before you kill the file, read the last three characters of the file
name to see if they are 'tmp'.  If they are, don't kill the file.  If they
aren't, then you can proceed and delete the file.

Best Wishes,
Jesse Olson


Quote:
>Dear all, I'm trying to clean up the Windows\Temp directory but as you know
>there are files which can't be accessed because they're in use by Windows.
>So if I try Kill, I would only get Access runtime error. So instead I
>specify the file types to delete, but then there are files that have no
>extension. Is there a way to specify "anything but *.tmp" in VB? Or better,
>"anything that's not in use by Windows"? The crude code I'm using at the
>moment
>is:

>    File2.Pattern = "*.doc;*.htm;*.html;*.exe;*.txt;*.zip;*.pdf"
>    File2.Path = WinTmpDir
>    For i = 0 To File2.ListCount - 1
>        Kill (File2.Path & "\" & File2.List(i))
>    Next

>Thanks,
>            Jules

>***24 hours in a day...24 beers in a case...coincidence?***



Wed, 15 Aug 2001 03:00:00 GMT  
 How to delete files in Windows\Temp?
For your particular case, simply put
   On Error Resume Next
at the beginning of the Procedure doing the Kill method and nothing else
On-Error-wise is required. This will ignore ANY error that occurs and your
code will keep on executing until the end of the Procedure is reached. You
do not need any other error handling for this particular functionality.

The proper syntax for the way you attempted to write it is as follows:

    On Error Goto ErrorState
    File2.Pattern = "*.doc;*.htm;*.html;*.exe;*.txt;*.zip;*.pdf"
    File2.Path = WinTmpDir
    For i = 0 To File2.ListCount - 1
        Kill (File2.Path & "\" & File2.List(i))
    Next
    Exit Sub
ErrorState:
    Resume Next

This has the same functionality as is described in my first paragraph, but
uses more code to achieve it. The Exit Sub is important because it stops the
executing code from "falling" into the ErrorState functionality.
Generically, an On-Error routine would look like this

    On Error Goto ErrorHandler
    ' ... Put Your Code Here ...
LineLabel:
    ' ... More Code Here ...
    Exit Sub
ErrorHandler:
    ' ... Put any code needed to
    ' ... attend to the error here
    Resume                  \
    Resume Next          > Only use one of these
    Resume LineLabel   /

See Resume Statement in the VB Help files for more on which Resume is the
correct one to use.

Hope this helps.

Rick
=================

Quote:

>Yes, but how do I trap the error and skip that file? I'm a bit confused
with
>the logic... I tried this:

>On Error Goto ErrorState
>    File2.Pattern = "*.doc;*.htm;*.html;*.exe;*.txt;*.zip;*.pdf"
>    File2.Path = WinTmpDir
>    For i = 0 To File2.ListCount - 1
>        Kill (File2.Path & "\" & File2.List(i))
>ErrorState:
>    Next

>The logic seems ok but it won't work, I'll still get the file access denied
>error runtime message. And if I put ErrorState outside the For loop it'll
>just quit whenever I hit an error.....Please help......

>Thanx,
>            Jules

>*You cannot strengthen the weak by weakening the strong*



Wed, 15 Aug 2001 03:00:00 GMT  
 How to delete files in Windows\Temp?

Quote:

> Dear all, I'm trying to clean up the Windows\Temp directory but as you know
> there are files which can't be accessed because they're in use by Windows.

It probably not a good idea to try and delete files that are in use by
windows as the results could be unexpected...you could crash your
machine etc. etc...Try deleting them the standard way, trap your errors
with an ON ERROR. and just delete those that aren't in use.

Kris.



Thu, 16 Aug 2001 03:00:00 GMT  
 How to delete files in Windows\Temp?
Yes, but how do I trap the error and skip that file? I'm a bit confused with
the logic... I tried this:

On Error Goto ErrorState
    File2.Pattern = "*.doc;*.htm;*.html;*.exe;*.txt;*.zip;*.pdf"
    File2.Path = WinTmpDir
    For i = 0 To File2.ListCount - 1
        Kill (File2.Path & "\" & File2.List(i))
ErrorState:
    Next

The logic seems ok but it won't work, I'll still get the file access denied
error runtime message. And if I put ErrorState outside the For loop it'll
just quit whenever I hit an error.....Please help......

Thanx,
            Jules

*You cannot strengthen the weak by weakening the strong*



Thu, 16 Aug 2001 03:00:00 GMT  
 How to delete files in Windows\Temp?

Quote:

>Dear all, I'm trying to clean up the Windows\Temp directory but as you know
>there are files which can't be accessed because they're in use by Windows.

Use:

Dim TempDir As String
TempDir = "c:\windows\temp\"

Shell "deltree.exe /y " & TempDir, vbHide

For this code not to be leaving a copy of winoldap in memory
rightclick on c:\windwos\command\deltree.exe and check
the Close on exit checkbox in Program tab.

or use:

Dim RetVal As String
Dim TempDir As String
On Error Resume Next
TempDir = "c:\windows\temp\"

RetVal = Dir(TempDir, vbDirectory + vbArchive + vbHidden + vbNormal _
    + vbReadOnly + vbSystem)
Do
    SetAttr TempDir & RetVal, vbNormal
    If GetAttr(TempDir & RetVal) = vbDirectory Then
        Kill TempDir & RetVal & "\*.*"
        RmDir (TempDir & RetVal)
    Else
        Kill (TempDir & RetVal)
    End If
    RetVal = Dir
Loop Until RetVal = ""

and add this if you want to get rid of locked stuff in next reboot:

FileCopy "c:\autoexec.bat", "c:\autoexec.bak"
Open "c:\autoexec.bat" For Append As #1
Print #1, vbCr



Close #1

Considering Windows reboot rate you should have no trouble keeping temp
clean.

--
-= Tar =-



Thu, 16 Aug 2001 03:00:00 GMT  
 How to delete files in Windows\Temp?
I would say the safest thing to do is not to delete files under a few days
old...  Some files still may be "in use" by apps even though you ddon't get
file in use errors.  This is what the cleanup utility does that comes with
win98 - it only deletes files over a week old.

--
James Johnston

ICQ Contact Information:
My ICQ# is 20539613.  You can use this number to contact me using one of the
following methods:

* Page me online through my Personal Communication Center:
http://wwp.mirabilis.com/20539613
* Send me an E-mail Express message directly to my computer screen in real

* If you have ICQ installed, use my ICQ number:  20539613
Download ICQ at http://www.icq.com/

Quote:

>Dear all, I'm trying to clean up the Windows\Temp directory but as you know
>there are files which can't be accessed because they're in use by Windows.
>So if I try Kill, I would only get Access runtime error. So instead I
>specify the file types to delete, but then there are files that have no
>extension. Is there a way to specify "anything but *.tmp" in VB? Or better,
>"anything that's not in use by Windows"? The crude code I'm using at the
>moment
>is:

>    File2.Pattern = "*.doc;*.htm;*.html;*.exe;*.txt;*.zip;*.pdf"
>    File2.Path = WinTmpDir
>    For i = 0 To File2.ListCount - 1
>        Kill (File2.Path & "\" & File2.List(i))
>    Next

>Thanks,
>            Jules

>***24 hours in a day...24 beers in a case...coincidence?***

begin 666 James Johnston.vcf
M0D5'24XZ5D-!4D0-"E9%4E-)3TXZ,BXQ#0I..DIO:&YS=&]N.TIA;65S.SL[

M3#M73U)+.E5300T*0412.TA/344Z.SL[.SL[55-!#0I,04)%3#M(3TU%.E53
M00T*55),.FAT=' Z+R]W=W<N9V5O8VET:65S+F-O;2]3:6QI8V]N5F%L;&5Y
M+TAE:6=H=',O-S4S-2\-"D5-04E,.U!2148[24Y415).150Z:F]H;G-T;VXM
M:F%M97- =7-A+FYE= T*4D56.C$Y.3DP,S$R5# T,# Q,EH-"D5.1#I60T%2
#1 T*
`
end


Mon, 27 Aug 2001 03:00:00 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. How to delete files in Windows\Temp?

2. How to delete files in Windows\Temp?

3. Temp Files Not Deleting after closing Word 2002

4. Deleting a temp file

5. Auto-Delete Temp file

6. Deleting Temp internet files

7. Delete all temp internet files for all users

8. Delete temp.internet files ecc..(newbie)

9. How can I delete cookies and temp internet files w/VBS

10. Deleting Temp Internet files, new approach ?

11. Delete cookies and temp. inet files with VBS

12. Deleting Temp Internet Files via script

 

 
Powered by phpBB® Forum Software