Code: Select all
Sub Clear_All_Files_And_SubFolders_In_Folder()
'Delete all files and subfolders
'Be sure that no file is open in the folder
Dim fso As Object
Dim MyPath As String
Set fso = CreateObject("scripting.filesystemobject")
MyPath = CurrentDBDir & "Reports" '<< Change
If Right(MyPath, 1) = "\" Then
MyPath = Left(MyPath, Len(MyPath) - 1)
End If
If fso.FolderExists(MyPath) = False Then
MsgBox MyPath & " doesn't exist"
Exit Sub
End If
On Error Resume Next
'Delete files
fso.deletefile MyPath & "\*.*", True
'Delete subfolders
fso.deletefolder MyPath & "\*.*", True
On Error GoTo 0
End Sub
I've tried a few I've found online, but none seem to work properly...
Any suggestions?