Does anyone have a suggestion for speeding this up a ton?
It takes a given folder and adds to an array the path, size (in bytes, KB, MB, GB), sub folder counts, file counts. It recurses into subfolders. The array gets pushed in to a SQL database.
It works decently until I hit a subfolder with 10000 files, then it’s 5 to 10 minutes on that folder.
I’m guessing the bottleneck is creating a folderItem 10000 times? I’m betting an MBS plugin might help, but I can’t figure out which ?
Thanks, Bill
//ReadFolderItem(theFolder As FolderItem)
//Scans the selected folder and sub folders
//wrap all data in single quotes
//Adds folder stats data to sql
FolderCurrent = theFolder
//Exit is folder nil
If theFolder = Nil Or Not theFolder.Exists() Then
Return
End If
//Get the item count for this folder
var itemCount as Integer
itemCount = theFolder.Count
//Loop through the items in this folder
For i As Integer = 1 To itemCount
//Get the current item i as f
var f As FolderItem
f = theFolder.TrueItem(i)
//See if f is a folder or file
If f <> Nil Then
If f.Directory Then
//Add this folder stats to the array for the database row
Var MyData() As String
//Add this folder path while escaping single quotes
MyData.Add("'" + f.NativePath.ReplaceAll("'","''") + "'")
//Use plugin to get folder stats
Var d as DirectorySizeMBS = f.CalculateDirectorySizeMBS(True,0)
//Check that stats are available. Some folders are symlinks and will have nil details
if d <> nil Then
//Not a virtual dir, so we have stats
MyData.Add("'" + d.PhysicalTotalSize.ToString + "'")
MyData.Add("'" + Format(d.VisiblePhysicalTotalSize/1024,"0") + "'")
MyData.Add("'" + Format(d.VisiblePhysicalTotalSize/1048576,"0") + "'")
MyData.Add("'" + Format(d.VisiblePhysicalTotalSize/1073741824,"0") + "'")
MyData.Add("'" + d.FolderCount.ToString + "'")
MyData.Add("'" + d.FilesCount.ToString + "'")
else
//d was nil, so probably a symlink dir. Supply nils
MyData.Add("'" + "nil" + "'")
MyData.Add("'" + "nil" + "'")
MyData.Add("'" + "nil" + "'")
MyData.Add("'" + "nil" + "'")
MyData.Add("'" + "nil" + "'")
MyData.Add("'" + "nil" + "'")
end if
//add to sql database
InsertToDb(MyData)
//Recursion into folder for children folder
ReadFolderItems(f)
Else
//Must be a file. Ignore for this purpose
End If
End If
Next