Photo Gallery Member List Search Calendars FAQ Ticket List Log Out


Another delete temp files script advice needed

 
Logged in as: Guest
arrSession:exec spGetSession 2,2,60166
 Active Users: There are 0 members and 0 guests.
 Users viewing this topic: none
 

 

 
  
  Printable Version
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Another delete temp files script advice needed
  Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Page: [1]
Login
Message << Older Topic   Newer Topic >>
 Another delete temp files script advice needed - 5/13/2008 2:39:26 PM   
  colossus610

 

Posts: 2
Score: 0
Joined: 5/7/2008
Status: offline
I "discovered" VBScripting about 6 months ago and almost blew a cranial artery with how much time some of the more basic scripts saved me.
Logon, defrag, automate- oh my.
I can only start by saying I wholeheartedly appreciate the scripts I use now and written by those with seemingly endless knowledge compared to my own.

I sorta hacked together a delete temp file script from many different sources  and intended for it to delete all temporary files in

C:\Documents and Settings\*USERNAME*\Recent
C:\Documents and Settings\*USERNAME*\Local Settings\Temp
C:\Documents and Settings\*USERNAME*\Local Settings\Temporary Internet Files\
C:\C:\Documents and Settings\*USERNAME*\Local Settings\Temporary Internet Files\Content.IE5

and run a counter while in each folder then log the end result deleted file count for each directory.
The Event is logged as such:

77 Recent files were deleted
151 Temp files were deleted
1 Internet Files were deleted
Script ran for 0.31 seconds.
 
I have since given up on improving this script due to the fact that no matter what I do to the "Internet Files" portion, the deleted file count never gets higher than "1", it will delete all of the thousands of files in that directory but it never counts 'em.
So I was wondering if anyone could look over this and possibly offer some advice as to what my malfunction is in regards to the file count? Also maybe some general advice as to what I could do different/better?

Believe me, when I found this site, it was like I was 8 again, had 20 bucks and happened to land in the candy store. I looked and found and downloaded and searched and giggled a little too, I think.
I found and read the posts
http://www.visualbasicscript.com/m_27592/mpage_1/key_temp%2cfiles/tm.htm#27601

(and the Readme First, I DO read those) and I searched, which led me to this post:
http://www.visualbasicscript.com/m_32342/mpage_1/key_Cache/tm.htm#32342 (OMG, the environment variables and directories I forgot needed to be scrubbed!, that one got bookmarked to the desktop)

Back on topic(and the whole point);
1. Could I ask for some help on the file count thing?
2. And any "big brotherly" advice on the general code itself?

      


I know it's messy. Go ahead, snicker or flat out laugh. If I could find a printer that used finger paint, I'd use it to print this all out and slap it on the fridge. 
Oh yeah, I have ZERO programming/scripting/coding experience whatsoever, I'm a hardware guy turning network/system admin. I may not know all of the terms or names of stuff, but it seems to make sense in my head.

< Message edited by colossus610 -- 5/13/2008 2:40:43 PM >
 
 
Post #: 1
 
 RE: Another delete temp files script advice needed - 5/13/2008 7:21:53 PM   
  mcnd

 

Posts: 23
Score: 0
Joined: 4/27/2008
Status: offline
There's a difference betwen files in "temporary internet files" namespace and files in "temporary internet files" folder

I hope  this may explain your problem


      

(in reply to colossus610)
 
 
Post #: 2
 
 RE: Another delete temp files script advice needed - 5/14/2008 11:34:46 AM   
  colossus610

 

Posts: 2
Score: 0
Joined: 5/7/2008
Status: offline
Thank you, all squared away now.
Your help also made me realize that it is counting the files regardless of whether it's successfully deleting them or not......will look into this.
As for the general code itself, anything I could be doing better?

< Message edited by colossus610 -- 5/14/2008 11:35:51 AM >

(in reply to mcnd)
 
 
Post #: 3
 
 RE: Another delete temp files script advice needed - 5/14/2008 5:52:51 PM   
  ehvbs

 

Posts: 2114
Score: 50
Joined: 6/22/2005
From: Germany
Status: offline
Hi colossus610,

as you asked:

(1) don't use "On Error Resume Next" globally, but restrict it to the line(s)
     you are expecting problems from

(2) don't mix Subs/Functions into your top level code as you did here:

         ...
          Next
         'Delete all emptied SubFolders
         Sub KillSubFolders (SubPath)
           objFSO.DeleteFolder SubPath
         End Sub
         endTime = Timer
         ...

(3) where do you check for emptiness of the folder you are going to delete?

(4) don't rely on default properties: this

        Call KillSubFolders (objSubFolder)

   passes a folder object to KillSubFolders; this

       objFSO.DeleteFolder SubPath

    expects the name of the folder to delete. Thinking about the datatypes
    can result in better code: e.g. why not use the SubFolder's .Delete
    method instead of FSO.DeleteFolder?

(5) use better variable names; "i" may be ok in a counting loop, but the
     entity you named "f" is too important for your script to be named
     in such a disrespectful way.

(6) Consider to keep the Dim, Init, and Use of your variables as close
     together as possible: e.g. you don't need startTime (why not dtStart
     like objFSO?) before the loop, so

         [a long list of Dims]
         ... lots of code (1) ....
        Dim startTime : startTime = Timer
         ... lots of code (2) ....
         Dim runTime : runTime = round(Timer - startTime, 2)
         ... lots of code (3) ....
         WScript.Echo  .... runTime ...

      This way you have to remember/think of runTime across one 'lots of code'
      block, not three.

Regards

ehvbs

   

   

    

          

(in reply to colossus610)
 
 
Post #: 4
 
 
 
  

If you found our site useful please link to us <a href="http://www.visualbasicscript.com">VisualBasicScript.com</a>.
All Forums >> [Scripting] >> WSH & Client Side VBScript >> Another delete temp files script advice needed Page: [1]
Jump to:





New Messages No New Messages
Hot Topic w/ New Messages Hot Topic w/o New Messages
Locked w/ New Messages Locked w/o New Messages
 Post New Thread
 Reply to Message
 Post New Poll
 Submit Vote
 Delete My Own Post
 Delete My Own Thread
 Rate Posts