I am looking for a way to fetch the total file count in a directory tree.
Right now, to get the total file count, I am using the GetObjectHandles method to loop through the directories recursively while adding the total length of the handles in each directory.
something like this
func getTotalFile(parentId) int64 {
handles := mtp.Uint32Array{}
dev.GetObjectHandles(storageId, mtp.GOH_ALL_ASSOCS, parentId, &handles)
if isDirectory {
total = getTotalFile(parentId)
}
return len(handles) + total
}
This is very slow if the directory tree is large and wasting a lot of time processing the files.
I see a GetNumObjects method in op.go file but it doesn't return the total files in the directory tree.
What's the best and efficient way to find the total number of files in a directory, recursively?
I am looking for a way to fetch the total file count in a directory tree.
Right now, to get the total file count, I am using the
GetObjectHandles
method to loop through the directories recursively while adding the total length of thehandles
in each directory.something like this
This is very slow if the directory tree is large and wasting a lot of time processing the files.
I see a
GetNumObjects
method in op.go file but it doesn't return the total files in the directory tree.What's the best and efficient way to find the total number of files in a directory, recursively?
I'd appreciate any suggestions