rhino4eva
Active Member
- Joined
- Apr 1, 2009
- Messages
- 262
- Office Version
- 2010
- Platform
- Windows
Sub Autpen()
Dim FolderPath As String, path As String, NumOfFiles As Integer
If MsgBox("Do you need to change the age limit ?", vbYesNo + vbQuestion) = vbYes Then End
For x = 1 To Sheets("Sheet1").Range("f1")
Dir_Path = Sheets("Sheet1").Range("g" & x + 1)
Set imaxage = Sheets("Sheet1").Range("d1") ' changeable number of days
Set oFSO = CreateObject("Scripting.FileSystemObject")
MsgBox "Inspecting " & Dir_Path & " for antique files"
path = FolderPath & "\*.*"
Filename = Dir(path)
Do While Filename <> ""
Filename = Dir()
Loop
If oFSO.FolderExists(Dir_Path) Then 'Check that the folder exists
For Each ofile In oFSO.GetFolder(Dir_Path).Files
If DateDiff("d", ofile.DateLastModified, Now) > imaxage Then 'Look at each file to check if it is older than 10 days
age = DateDiff("d", ofile.DateLastModified, Now) ' calculate the age
'If age > 150 Then End
If MsgBox("Delete " & ofile & " because its " & age & " old", vbYesNo + vbQuestion) = vbYes Then ' do yo weant to delete it
ofile.Delete
Else: End If
End If
Next
End If
Next x
End Sub
so i have a piece of vba code to search thru a list of directories (column G) and delete files older than 10 days old
however i would like to save certain files whose age is greater that 10 days,these are listed in column I
instead of "ending " as i have it now , how would i be able to weave a "do not delete is in this list(I) " into the code
Dim FolderPath As String, path As String, NumOfFiles As Integer
If MsgBox("Do you need to change the age limit ?", vbYesNo + vbQuestion) = vbYes Then End
For x = 1 To Sheets("Sheet1").Range("f1")
Dir_Path = Sheets("Sheet1").Range("g" & x + 1)
Set imaxage = Sheets("Sheet1").Range("d1") ' changeable number of days
Set oFSO = CreateObject("Scripting.FileSystemObject")
MsgBox "Inspecting " & Dir_Path & " for antique files"
path = FolderPath & "\*.*"
Filename = Dir(path)
Do While Filename <> ""
Filename = Dir()
Loop
If oFSO.FolderExists(Dir_Path) Then 'Check that the folder exists
For Each ofile In oFSO.GetFolder(Dir_Path).Files
If DateDiff("d", ofile.DateLastModified, Now) > imaxage Then 'Look at each file to check if it is older than 10 days
age = DateDiff("d", ofile.DateLastModified, Now) ' calculate the age
'If age > 150 Then End
If MsgBox("Delete " & ofile & " because its " & age & " old", vbYesNo + vbQuestion) = vbYes Then ' do yo weant to delete it
ofile.Delete
Else: End If
End If
Next
End If
Next x
End Sub
so i have a piece of vba code to search thru a list of directories (column G) and delete files older than 10 days old
however i would like to save certain files whose age is greater that 10 days,these are listed in column I
instead of "ending " as i have it now , how would i be able to weave a "do not delete is in this list(I) " into the code