Solved

Need VBScript code to Delete Multiple Files at once.

Posted on 2007-04-05
6
675 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
ID: 18861692
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
ID: 18861702
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
ID: 18865283
I am getting this error returned.

Object doesn't support this property or method
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 67

Expert Comment

by:sirbounty
ID: 18865293
What line number?
0
 
LVL 67

Expert Comment

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

Expert Comment

by:sirbounty
ID: 18867626
Happy to help - thanx.
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VBA & VBSCRIPT: re-adapt log file 13 33
Creating An Intelligent Dropdown 8 42
Create Consolidation Sheet 3 38
IDENTIFY, THEN ADD TOGETHER AND DELETE ONE, EXCEL 3 20
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 …
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

821 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