Solved

Need VBScript code to Delete Multiple Files at once.

Posted on 2007-04-05
6
700 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 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

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…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

690 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