I already created a recursive function to get the size of the directory in the folder path. It works, however, with the growing number of directories I have to look for (and the number of files in each corresponding folder), this is a very slow, inefficient method.
static string GetDirectorySize(string parentDir) { long totalFileSize = 0; string[] dirFiles = Directory.GetFiles(parentDir, "*.*", System.IO.SearchOption.AllDirectories); foreach (string fileName in dirFiles) {
This looks for all the subdirectories for the argument path, so the dirFiles array becomes quite large. Is there a better way to do this? I searched but found nothing.
Another idea that crossed my mind was to put the results in the cache, and when the function is called again, try to find the differences and only rename the folders that were changed. Not sure if this is good ...
c # directory search recursion
ikathegreat
source share