.net - Listing directories by content size using C# -


i'm trying list folders of c drive excluding document folder not seem have access to. first seemed rather simple me found myself still struggling despite seemingly rich .net library.

i can't post code have tried far not work.

hope suggest something.

a small example here:

class directorysize {     public string directoryname;     public long directorysizes; }  public class program {     static void main(string[] args)     {         string[] cdirectories = directory.getdirectories("c:\\");          list<directorysize> listsizes = new list<directorysize>();          (int = 0; < cdirectories.length; i++)         {             long size = getdirectorysize(cdirectories[i]);              if(size != -1)             {                 listsizes.add(new directorysize() { directoryname = cdirectories[i], directorysizes = size });             }         }     }      private static long getdirectorysize(string folderpath)     {         try         {            directoryinfo di = new directoryinfo(folderpath);            return di.enumeratefiles("*", searchoption.alldirectories).sum(fi => fi.length);         }         catch         {            // if access denied error handle here            return -1;         }     } } 

Comments

Popular posts from this blog

javascript - Google App Script ContentService downloadAsFile not working -

javascript - Function overwritting -

c# - Exception when attempting to modify Dictionary -