Message 1 of 4
Delete Old Version file and folders
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi,
First off, if this topic gets escalated I'm sorry but I'm not doing that. It just happens somehow...
I use underneath code to find old versions folders. This works fine but I need to delete the files and the folder. I tried to do it with "Kill" but it give me error 75 Path file access error. Some help would be great! Thanks in advance...
Sub FindAndKillOldVersions()
'Call LoopAllSubFolders Macro to start to procedure
Call LoopAllSubFolders("I:\Inventor libraries\Inventor")
End Sub
'List all files in sub folders
Sub LoopAllSubFolders(ByVal folderPath As String)
Dim fileName As String
Dim fullFilePath As String
Dim numFolders As Long
Dim folders() As String
Dim i As Long
If Right(folderPath, 1) <> "\" Then folderPath = folderPath & "\"
fileName = Dir(folderPath & "*.*", vbDirectory)
While Len(fileName) <> 0
If Left(fileName, 1) <> "." Then
fullFilePath = folderPath & fileName
If (GetAttr(fullFilePath) And vbDirectory) = vbDirectory Then
ReDim Preserve folders(0 To numFolders) As String
folders(numFolders) = fullFilePath
numFolders = numFolders + 1
Else
'Insert the actions to be performed on each file
If InStrRev(folderPath, "OldVersions") Then
'Debug.Print folderPath
'Delete Files first
Kill folderPath & "\*"
'Delete folder
RmDir folderPath
End If
End If
End If
fileName = Dir()
Wend
For i = 0 To numFolders - 1
LoopAllSubFolders folders(i)
Next i
End Sub
---------------------------------------------------------------------------------------------------------