Delete Old Version file and folders

Delete Old Version file and folders

Frank-Oosterwaal
Collaborator Collaborator
1,764 Views
3 Replies
Message 1 of 4

Delete Old Version file and folders

Frank-Oosterwaal
Collaborator
Collaborator

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


 

---------------------------------------------------------------------------------------------------------
0 Likes
1,765 Views
3 Replies
Replies (3)
Message 2 of 4

bradeneuropeArthur
Mentor
Mentor

Because Oldversion folder contains hidden elements and folders.

Regards,

Arthur Knoors

Autodesk Affiliations & Links:
blue LinkedIn LogoSquare Youtube Logo Isolated on White Background


Autodesk Software:Inventor Professional 2025 | Vault Professional 2024 | Autocad Mechanical 2024
Programming Skills:Vba | Vb.net (Add ins Vault / Inventor, Applications) | I-logic
Programming Examples:
Drawing List!|
Toggle Drawing Sheet!|
Workplane Resize!|
Drawing View Locker!|
Multi Sheet to Mono Sheet!|
Drawing Weld Symbols!|
Drawing View Label Align!|
Open From Balloon!|
Model State Lock!
Posts and Ideas:
My Ideas|
Dimension Component!|
Partlist Export!|
Derive I-properties!|
Vault Prompts Via API!|
Vault Handbook/Manual!|
Drawing Toggle Sheets!|
Vault Defer Update!

! For administrative reasons, please mark a "Solution as solved" when the issue is solved !


 


EESignature

0 Likes
Message 3 of 4

dgreatice
Collaborator
Collaborator
Hi,

Are this code running at inventor already open?

There are 1 oldversion file and folder for *.ipj, and you cant delete it because inventor still running.

Why just not try old method delete from windows explorer?
Please use the ACCEPT AS SOLUTION or KUDOS button if my Idea helped you to solve the problem.

Autodesk Inventor Professional Certified 2014
0 Likes
Message 4 of 4

Anonymous
Not applicable

I think you need to try Long Path Tool for deleting unwanted files. Works great for me. I hope it helps you.

0 Likes