A year and a half ago, I decided that I was going to make a change to my KwikOpen add-in to get rid of recent files that no longer exist. Well, I finally got it done. No, it didn’t take that long to implement. The performance of the add-in has been fine so there wasn’t a pressing need. The other day, the addin seemed a little less peppy than usual and I thought it was time for a look.
I had 2,368 files in my MRU and 465 of them are dead links. That’s about 20% and it’s similar to the proportion I saw back in February 2015. Of the three options I listed at the bottom of my previous post, I chose none of them. Instead, I weeded out some files as I wrote them back out to disk.
Public Sub WriteToDisk()
Dim sFile As String
Dim lFile As Long
Dim clsRcntFile As CRcntFile
Dim aFiles(1 To 3000) As String
Dim lFileCnt As Long
Dim lWriteCnt As Long
Const dWEEDLIMIT As Double = 0.9
For Each clsRcntFile In Me
lFileCnt = lFileCnt + 1
If lFileCnt < Me.Count * dWEEDLIMIT Or clsRcntFile.Exists Then
lWriteCnt = lWriteCnt + 1
aFiles(lWriteCnt) = clsRcntFile.FullName
If lWriteCnt >= UBound(aFiles) Then Exit For
sFile = Environ$("APPDATA") & "\Microsoft\Addins\" & msMRUFILE
lFile = FreeFile
Open sFile For Output As lFile
Print #lFile, Join(aFiles, vbNewLine)
The file names are written to the file with the most recent at the top – sort of. Because I’m using the built-in MRU as well as my own, it’s not exactly that way, but it’s close enough for government work. Instead of time stamping the entries, I decided to dump any nonexistent files that were near the bottom of the list. If a file is in the top 90% of the list, it stays regardless of whether it exists. If it’s in the bottom 10%, it only stays if it’s still where it was.
|Iteration||Total Files||Orphaned Files|
Looking at the last 100 or so files, they’re mostly from 2014. I could cap this at 2,000 and probably not notice.