Solved

Need VBScript code to Delete Multiple Files at once.

Posted on 2007-04-05
6
640 Views
Last Modified: 2013-11-25
Through VBScript I need to delete multiple files using wildcards as the files that need to be deleted are numbered or called something different dependent upon the type of data contained in the file.  The one common value is the Id.  I can delete a single file no problem - but have not found a way within VBScript to delete files based on a wildcard.  I could have a file, RID123.xml and a file CID123Drill.xml and a file called RID123Drill1.xml, RID123Drill2.xml..  What I don't know is the RID123Drill1 or Drill2 as these # are random - I don't know them.  So what I am hoping to do is DELETE(RID123Drill*.XML) or something similar.
0
Comment
Question by:DougR_MS
  • 5
6 Comments
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Since this is data destructive - please test in a test folder first...

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder=objFSO.GetFolder("C:\YourFolder\")
For Each File in objFolder.Files
  If lCase(objFSO.GetExtensionName(file))="xml" Then
    If lCase(Left(file.name,11))="rid123drill" Then objFSO.DeleteFile file
  End If
Next
Set objFolder=Nothing
Set objFSO=Nothing
0
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
Comment Utility
Actually fso does support wildcards as well...

Dim objFSO:Set objFSO=CreateObject("Scripting.FileSystemObject")
Dim objFolder: Set objFolder=objFSO.GetFolder("C:\YourFolder\")
objFSO.DeleteFile objFolder.Path & "\RID123Drill*.xml"
Set objFolder=Nothing
Set objFSO=Nothing
0
 

Author Comment

by:DougR_MS
Comment Utility
I am getting this error returned.

Object doesn't support this property or method
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
What line number?
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Which version?  The 2nd one is faster and should work for what you want...
0
 
LVL 67

Expert Comment

by:sirbounty
Comment Utility
Happy to help - thanx.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now