|
-
Aug 21st, 2009, 04:18 AM
#1
Thread Starter
Frenzied Member
[EXCEL] Kill FSO or API
I want to remove all xml files in a temporary directory before proceeding with my macro.
What is the preferred method?
Kill is a one liner but will throw a run time error if there are no xml files in the directory.
FSO will require a runtime dependency (although I already have Scripting Runtime for Dictionary)
Code:
Public Sub DeleteFiles(strFolderName As String, strType As String)
Dim fso As Scripting.FileSystemObject
Dim fsoDir As Scripting.Folder
Dim fsoFile As Scripting.File
Set fso = New Scripting.FileSystemObject
Set fsoDir = fso.GetFolder(strFolderName)
For Each fsoFile In fsoDir.Files
If fsoFile.Type = strType Then
fsoFile.Delete
End If
Next fsoFile
End Sub
Not familiar with the API to delete all files of a certain type in a directory.
-
Aug 21st, 2009, 04:27 AM
#2
Re: [EXCEL] Kill FSO or API
you can use kill, just check if file exists first
if len(dir("c:\tmp\*.xml"))>0 then kil l"c:\tmp\*.xml"
i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next
dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part
come back and mark your original post as resolved if your problem is fixed
pete
-
Aug 21st, 2009, 04:32 AM
#3
Re: [EXCEL] Kill FSO or API
Or you can use this... One situation where there is no harm in using On Error Resume Next
vb Code:
'~~> If File not found ignore error On Error Resume Next Kill "c:\tmp\*.xml" '~~> Immediately set it back to normal On Error GoTo 0
A good exercise for the Heart is to bend down and help another up...
Please Mark your Thread " Resolved", if the query is solved
MyGear:
★ CPU ★ Ryzen 5 5800X
★ GPU ★ NVIDIA GeForce RTX 3080 TI Founder Edition
★ RAM ★ G. Skill Trident Z RGB 32GB 3600MHz
★ MB ★ ASUS TUF GAMING X570 (WI-FI) ATX Gaming
★ Storage ★ SSD SB-ROCKET-1TB + SEAGATE 2TB Barracuda IHD
★ Cooling ★ NOCTUA NH-D15 CHROMAX BLACK 140mm + 10 of Noctua NF-F12 PWM
★ PSU ★ ANTEC HCG-1000-EXTREME 1000 Watt 80 Plus Gold Fully Modular PSU
★ Case ★ LIAN LI PC-O11 DYNAMIC XL ROG (BLACK) (G99.O11DXL-X)
★ Monitor ★ LG Ultragear 27" 240Hz Gaming Monitor
★ Keyboard ★ TVS Electronics Gold Keyboard
★ Mouse ★ Logitech G502 Hero
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|