Tim Hanson
Member
I have a folder with multiple files of different names and all have multiple copies differing by date and time they were generated, the macro kills all the files leaving only the newest files of any name
In the folder I have another folder called OldFiles I need to move the old files to this folder instead of killing them, I have tried but can not get how to do this
Thanks
In the folder I have another folder called OldFiles I need to move the old files to this folder instead of killing them, I have tried but can not get how to do this
Thanks
Code:
Sub DirKiller()
Dim f As String, FName As String, K, N As Long, S As String
f = ThisWorkbook.path & "\Files to Combine\": FName = dir(f)
RunDirectory: If FName = "" Then GoTo Killem
S = S & FName
S = S & vbCrLf
FName = dir(): GoTo RunDirectory
Killem: K = Split(S, vbCrLf)
DownBubble: For N = LBound(K) To UBound(K) - 1
If K(N + 1) > K(N) Then
S = K(N): K(N) = K(N + 1): K(N + 1) = S
GoTo DownBubble: End If: Next N: S = K(0)
For N = 1 To UBound(K)
Garrotte: If N > UBound(K) Then Exit Sub
If Len(S) = Len(K(N)) Then
Kill f & K(N)
Else:
S = K(N): N = N + 1: GoTo Garrotte
End If: Next N
End Sub