Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Files size?

Files size?

Scheduled Pinned Locked Moved C#
tutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    Muammar
    wrote on last edited by
    #1

    Hi, any idea how to calculate files size found in some folder??

    string[] arSourceFiles = System.IO.Directory.GetFiles(MyDir);
    arSourceFiles.(:confused:);


    Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

    M M 2 Replies Last reply
    0
    • M Muammar

      Hi, any idea how to calculate files size found in some folder??

      string[] arSourceFiles = System.IO.Directory.GetFiles(MyDir);
      arSourceFiles.(:confused:);


      Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

      M Offline
      M Offline
      Mandaar Kulkarni
      wrote on last edited by
      #2

      Try This.... foreach (string file in arSourceFiles) { FileInfo finfo = new FileInfo(file); int filesize = finfo.Length; // Length returns the size of file. }

      M 1 Reply Last reply
      0
      • M Mandaar Kulkarni

        Try This.... foreach (string file in arSourceFiles) { FileInfo finfo = new FileInfo(file); int filesize = finfo.Length; // Length returns the size of file. }

        M Offline
        M Offline
        Muammar
        wrote on last edited by
        #3

        Looks good enough:) thank you Mandaar:rose:


        Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

        1 Reply Last reply
        0
        • M Muammar

          Hi, any idea how to calculate files size found in some folder??

          string[] arSourceFiles = System.IO.Directory.GetFiles(MyDir);
          arSourceFiles.(:confused:);


          Smile: A curve that can set a lot of things straight! (\ /) (O.o) (><)

          M Offline
          M Offline
          Martin 0
          wrote on last edited by
          #4

          Hello, If you also whant to look in the folders of you main folder, you have to go threw it recursive! Like this:

          	private double GetFileSize(DirectoryInfo di, double currentsize)
          	{
          		double actsize = currentsize;
          		FileInfo\[\] AllFiles = di.GetFiles();
          		DirectoryInfo\[\] AllDirectories = di.GetDirectories();
          		
          		foreach(FileInfo fi in AllFiles)
          		{
          			actsize = actsize + fi.Length;
          		}
          
          		foreach(DirectoryInfo dinew in AllDirectories)
          		{
          			actsize = GetFileSize(dinew, actsize);
          		}
          
          		return actsize;
          	}
          

          I think there is some feature in .Net >1.1 which does that. Hope it helps! All the best, Martin

          S 1 Reply Last reply
          0
          • M Martin 0

            Hello, If you also whant to look in the folders of you main folder, you have to go threw it recursive! Like this:

            	private double GetFileSize(DirectoryInfo di, double currentsize)
            	{
            		double actsize = currentsize;
            		FileInfo\[\] AllFiles = di.GetFiles();
            		DirectoryInfo\[\] AllDirectories = di.GetDirectories();
            		
            		foreach(FileInfo fi in AllFiles)
            		{
            			actsize = actsize + fi.Length;
            		}
            
            		foreach(DirectoryInfo dinew in AllDirectories)
            		{
            			actsize = GetFileSize(dinew, actsize);
            		}
            
            		return actsize;
            	}
            

            I think there is some feature in .Net >1.1 which does that. Hope it helps! All the best, Martin

            S Offline
            S Offline
            szukuro
            wrote on last edited by
            #5

            Martin# wrote:

            I think there is some feature in .Net >1.1 which does that.

            Actually it's just a new overload for the GetFiles method. http://msdn2.microsoft.com/en-us/library/ms143327(vs.80).aspx[^]

            M 1 Reply Last reply
            0
            • S szukuro

              Martin# wrote:

              I think there is some feature in .Net >1.1 which does that.

              Actually it's just a new overload for the GetFiles method. http://msdn2.microsoft.com/en-us/library/ms143327(vs.80).aspx[^]

              M Offline
              M Offline
              Martin 0
              wrote on last edited by
              #6

              Yep, Thanks for the info

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups