Sub DeletFiles ()
Dim Fso As FileSystemObject
Dim Fldr As Folder
Dim Fpath As String
Dim Fl As File
Application.DisplayAlerts = False
Set Fso = New FileSystemObject
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
Fpath = .SelectedItems(1)
End With
Set Fldr = Fso.GetFolder(Fpath)
ans = MsgBox("Press yes to delete or No to cancel", vbYesNo)
For Each Fl In Fldr.Files
If ans = vbYes Then
Fl.Delete
Else
Exit Sub
End If
Next Fl
MsgBox "File Deleted", vbInformation
End Sub
Thanks & regards,
Vikas Verma
No comments:
Post a Comment