[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Need VBScript code to Delete Multiple Files at once.

Posted on 2007-04-05
6
Medium Priority
?
733 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

Question has a verified solution.

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

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
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…
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…
Suggested Courses

650 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