• Home
  • Billiards
  • Classic ASP
  • Browse Blog
    • Halifax
    • Internet
    • Internet Marketing
    • Programming
    • SEO
    • sitemap
    • Skateboarding
    • technology
      • Automation
    • travel
    • Web Development
    • Web Hosting
    • Website Management
    • wedding
  • Subscribe via RSS

Delete Cache VBS VBScript to Delete all Files in a Folder

April 10th, 2009  |  Published in Programming, technology




This is a simple VBS VBScript that I use to delete all files in a given folder on a machine. It is particularly useful to delete internet cache files or cookies. You can set a scheduled job actually, to perform this task nightly. This script could be easily modified to, say, clear out your temporary internet files from the folder used by internet explorer. This example is a vbs vbscript to delete files in a temporary folder called “downloads” contained within my “My Documents” folder.

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
' VB Script Document, VBS, WSH, wscript
' Deletes files in a specified folder, for example, a temp downloads folder.
' By GR, February 27, 2009.
' robarspages.ca
 
'Declare variables
Dim strCacheFile
Dim strComputer
Dim strAppData
Dim strUserProfile
Dim strErrorfile
 
Dim objWMIService
Dim objShell
Dim objFSO
Dim objFolder
 
StrcacheFile = "\downloads\"
strComputer = "." 'leave alone if running script on same maching
 
Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set objShell = CreateObject( "WScript.Shell" )
 
 '---path to the application data folder. not used in this example.
strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%")
'---path to the user folder (if multiple users)
strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%") 
 
Set objFSO = CreateObject("Scripting.FileSystemObject")
 
' get the folder that contains the folder you want to empty.
Set objFolder = objFSO.GetFolder(strUserProfile & "\My Documents")
 
If objFSO.FolderExists(objFolder & StrcacheFile) Then
    objFSO.DeleteFile(objFolder & StrcacheFile & "*"), True
    WScript.Echo "Folder """ & objFolder & StrcacheFile & """ was emptied successfully"
else
    WScript.Echo "ERROR: I could not find the folder, please check the path..."
End If
 
 ' Clean up objects
Set objWMIService = Nothing
Set objShell = Nothing
Set objFSO = Nothing
Set objFolder = Nothing

' VB Script Document, VBS, WSH, wscript ' Deletes files in a specified folder, for example, a temp downloads folder. ' By GR, February 27, 2009. ' robarspages.ca 'Declare variables Dim strCacheFile Dim strComputer Dim strAppData Dim strUserProfile Dim strErrorfile Dim objWMIService Dim objShell Dim objFSO Dim objFolder StrcacheFile = "\downloads\" strComputer = "." 'leave alone if running script on same maching Set objWMIService = GetObject("winmgmts:{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set objShell = CreateObject( "WScript.Shell" ) '---path to the application data folder. not used in this example. strAppData = objShell.ExpandEnvironmentStrings("%APPDATA%") '---path to the user folder (if multiple users) strUserProfile = objShell.ExpandEnvironmentStrings("%USERPROFILE%") Set objFSO = CreateObject("Scripting.FileSystemObject") ' get the folder that contains the folder you want to empty. Set objFolder = objFSO.GetFolder(strUserProfile & "\My Documents") If objFSO.FolderExists(objFolder & StrcacheFile) Then objFSO.DeleteFile(objFolder & StrcacheFile & "*"), True WScript.Echo "Folder """ & objFolder & StrcacheFile & """ was emptied successfully" else WScript.Echo "ERROR: I could not find the folder, please check the path..." End If ' Clean up objects Set objWMIService = Nothing Set objShell = Nothing Set objFSO = Nothing Set objFolder = Nothing

Leave a Response

Tags

1and1 adsense asp caribbean classic asp crowdsourcing CTR cuba Cueva de Pirata customer service database dominican republic forum management godaddy google Halifax hosting hotel ideagora Internet Linux MySQL objWmiService outsourcing php Pirates Cave plugin scripting scripts SEO Skateboarding sql travel Varadero vbs vbscript web browser web development wedding What is Crowdsourcing? wikipedia windows windows scripting winmgmts xp

Pages

  • About Robar’s Pages
    • Privacy Policy for robarspages.ca
  • Classic ASP Programming and Development
  • Gran Bahia Principe Wedding
  • YouTube Extension Plugins for WordPress

Categories

  • Automation
  • Halifax
  • Internet
  • Internet Marketing
  • Programming
  • SEO
  • sitemap
  • Skateboarding
  • technology
  • travel
  • Web Development
  • Web Hosting
  • Website Management
  • wedding

Recent Posts

  • HTTP_X_EAC_REQUEST
  • eZooms Bot User Agent
  • SQL Full Outer Join Three Tables
  • Classic ASP Data Caching for Performance
  • Comparing OLE DB and ODBC Connections

Recent Comments

  • AP on 1and1 Corporate Headquarters Phone Number
  • AJ on 1and1 Corporate Headquarters Phone Number
  • cordova on 1and1 Corporate Headquarters Phone Number
  • mike on 1and1 Corporate Headquarters Phone Number
  • David on Regex MM/YYYY Regular Expression for Credit Card Expiration Date
©2023 Robar's Pages
Sitemap and Table Of Contents