DELETING FILES WITH SPECIFIC EXTENSION IN a FOLDER

R

R VAN DEURSEN

I have a folder that contains generated .pdf files.
In the same folder there is after .pdf creation always a
second file of each pdf with the extension .apd.
I need a VB script that automatically searches for files
with the extension .apd in the same folder as the pdf,s
and deletes them.

There is already a peace of the script, but it is totally
wrong or incomplete.

Thank you so much.

Dim objFSO
Set objFSO = CreateObject
("Scripting.FileSystemObject")
objFSO.DeleteFile "G:\page
store\CERT_TIJDSCHRIFTEN_NL\*.apd"

Set objFSO = Nothing
Wscript.Quit
 
T

Tushar Mehta

The code below compiles OK, but is otherwise untested:

Option Explicit

Sub testIt()
Dim FSO As FileSystemObject, f As File
Set FSO = CreateObject("Scripting.FileSystemObject")
For Each f In FSO.GetFolder( _
"G:\page store\CERT_TIJDSCHRIFTEN_NL\").Files
If Len(f.Name) < 4 Then
ElseIf Right(f.Name, 4) = ".apd" Then
f.Delete
End If
Next f
End Sub

--
Regards,

Tushar Mehta
www.tushar-mehta.com
Excel, PowerPoint, and VBA add-ins, tutorials
Custom MS Office productivity solutions
 
O

OB1

I may have misuderstood but simpler still should be....

Sub doit()

Const cnstAPDFiles = "G:\page store\CERT_TIJDSCHRIFTEN_NL\*.apd"

If Dir(cnstAPDFiles) <> "" Then Kill cnstAPDFiles

End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top