Private Sub cmdYesD_Click() Dim File1 As File Dim Folder1 As Folder Dim FileCollection As Folder Dim fso As New FileSystemObject Dim strRegion2 As String Dim intDays2 As Integer Dim intDelete As Integer Dim intDeleteFolder As Integer Dim TotalFiles As Integer Dim ProcessedFiles As Integer strRegion2 = Me.txtRegionConf.Text intDays2 = Me.txtInputDays.Text ProcessedFiles = 0 'intDelete = 0 'intDeleteFolder = 0 'Deletes Files If fso.FolderExists("Z:\" & strRegion2 & "\Customer\Output") Then Set FileCollection = fso.GetFolder("Z:\" & strRegion2 & "\Customer\Output") 'Set progress bar maximum to files + folders TotalFiles = FileCollection.Files.Count + FileCollection.SubFolders.Count Me.ProgressBar1.Max = TotalFiles 'search for and delete files 'Call Cleanfiles For Each File1 In FileCollection.Files 'Move Progressbar ProcessedFiles = ProcessedFiles + 1 Me.ProgressBar1.Value = ProcessedFiles Do If DateDiff("d", FileDateTime(File1), Now) >= intDays2 Then fso.DeleteFile (File1) intDelete = intDelete + 1 End If Loop Next 'Next 'Call Cleanfolders For Each Folder1 In FileCollection.SubFolders 'Move Progressbar ProcessedFiles = ProcessedFiles + 1 Me.ProgressBar1.Value = ProcessedFiles Do Until TotalFiles If DateDiff("d", Folder1.DateCreated, Now) >= intDays2 Then fso.DeleteFolder (Folder1) intDeleteFolder = intDeleteFolder + 1 End If Loop Next MsgBox "Complete. Deleted: " & vbCrLf & intDelete & " files and " & vbCrLf & intDeleteFolders & " Folders" Else Call RegionError End If Me.Hide frmFFMMain.Show End Sub ________________________________________________________________________ Public Function RegionError() 'If fso.FolderExists("Z:\" & strRegion2 & "\Customer\Output") = False Then MsgBox "Error: Region not Found" Me.Hide frmFFMMain.Show 'End If End Function
Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.
”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.