C# Get file size of array with paths

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
7
down vote

favorite












I am new to arrays and I want to display the size (in MB) of multiple files into a textBox. The paths to the files are in an array.



var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);


I saw this code in another post to get the size of a file:



long length = new System.IO.FileInfo(file).Length;


How can I add all of the file sizes to an int/string and write them into the textBox?







share|improve this question






















  • MB is just FileInfoLength / (1024*1024)
    – fubo
    Aug 8 at 6:43










  • @loyd, does the below answers solve your problem or not?
    – ershoaib
    Aug 8 at 6:53














up vote
7
down vote

favorite












I am new to arrays and I want to display the size (in MB) of multiple files into a textBox. The paths to the files are in an array.



var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);


I saw this code in another post to get the size of a file:



long length = new System.IO.FileInfo(file).Length;


How can I add all of the file sizes to an int/string and write them into the textBox?







share|improve this question






















  • MB is just FileInfoLength / (1024*1024)
    – fubo
    Aug 8 at 6:43










  • @loyd, does the below answers solve your problem or not?
    – ershoaib
    Aug 8 at 6:53












up vote
7
down vote

favorite









up vote
7
down vote

favorite











I am new to arrays and I want to display the size (in MB) of multiple files into a textBox. The paths to the files are in an array.



var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);


I saw this code in another post to get the size of a file:



long length = new System.IO.FileInfo(file).Length;


How can I add all of the file sizes to an int/string and write them into the textBox?







share|improve this question














I am new to arrays and I want to display the size (in MB) of multiple files into a textBox. The paths to the files are in an array.



var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);


I saw this code in another post to get the size of a file:



long length = new System.IO.FileInfo(file).Length;


How can I add all of the file sizes to an int/string and write them into the textBox?









share|improve this question













share|improve this question




share|improve this question








edited Aug 8 at 6:40

























asked Aug 8 at 6:32









loyd

456




456











  • MB is just FileInfoLength / (1024*1024)
    – fubo
    Aug 8 at 6:43










  • @loyd, does the below answers solve your problem or not?
    – ershoaib
    Aug 8 at 6:53
















  • MB is just FileInfoLength / (1024*1024)
    – fubo
    Aug 8 at 6:43










  • @loyd, does the below answers solve your problem or not?
    – ershoaib
    Aug 8 at 6:53















MB is just FileInfoLength / (1024*1024)
– fubo
Aug 8 at 6:43




MB is just FileInfoLength / (1024*1024)
– fubo
Aug 8 at 6:43












@loyd, does the below answers solve your problem or not?
– ershoaib
Aug 8 at 6:53




@loyd, does the below answers solve your problem or not?
– ershoaib
Aug 8 at 6:53












5 Answers
5






active

oldest

votes

















up vote
7
down vote



accepted










If i understand you correctly, just use Linq Select and string.Join



var results = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories)
.Select(file => new FileInfo(file).Length);

TextBox1.Text = string.Join(", ", results);


if you want to sum them, just use Enumerable.Sum



 TextBox1.Text = $"results.Sum():N3";


Update



public static class MyExtension

public enum SizeUnits

Byte, KB, MB, GB, TB, PB, EB, ZB, YB


public static string ToSize(this Int64 value, SizeUnits unit)

return (value / (double)Math.Pow(1024, (Int64)unit)).ToString("0.00");



TextBox1.Text = results.Sum().ToSize();





share|improve this answer






















  • One more question, is there a way to get a decimal value? In my case a file has the size of 14.9 MB but I end up with 14 MB.
    – loyd
    Aug 8 at 8:24






  • 1




    @loyd yes you can use format specifiers. updated
    – TheGeneral
    Aug 8 at 8:26






  • 1




    @loyd you can read more about them here docs.microsoft.com/en-us/dotnet/standard/base-types/…
    – TheGeneral
    Aug 8 at 8:26










  • I used $"results.Sum() / (1024*1024):N3"; to get the file size in MB but the decimal value gets filled with zeros only. What is my mistake?
    – loyd
    Aug 8 at 9:49






  • 1




    @loyd you could use $"results.Sum() / (double)(1024*1024):N3", or i updated my answer if you want to get fancy
    – TheGeneral
    Aug 8 at 9:50


















up vote
2
down vote













If you don't want to add complexity by using LINQ and want to practice with arrays:



var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);

long length = 0;

for (int i = 0; i < Files.Length; i++)

length += new FileInfo(Files[i]).Length;






share|improve this answer





























    up vote
    0
    down vote













    The below code may work to you.



    var FilesAndSizes = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories).Select(item => new KeyValuePair<string,int>(item, new System.IO.FileInfo(item).Length));





    share|improve this answer



























      up vote
      0
      down vote













      Using Directory.EnumerateFiles you're able to calculate the total size while only traversing the array once.



      To get the total size for all files of an extension:



      long totalSizeInBytes = 0;
      foreach(var file in Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories))

      totalSizeInBytes += new FileInfo(file).Length;



      To get a list of all file sizes:



      var results = Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories)
      .Select(file => new FileInfo(file).Length);

      TextBox1.Text = string.Join(", ", results);





      share|improve this answer



























        up vote
        0
        down vote













        i think that DirectoryInfo object cuold be smarter for your case istead of Directory object.



        Look at that example:



        public static void Main()

        string filetype = ".jpg";

        // Make a reference to a directory.
        DirectoryInfo di = new DirectoryInfo("c:\");
        // Get a reference to each file in that directory.
        FileInfo fiArr = di.GetFiles("*" + filetype, SearchOption.AllDirectories);
        // Display the names and sizes of the files.
        Console.WriteLine("The directory 0 contains the following files:", di.Name);
        foreach (FileInfo f in fiArr)
        Console.WriteLine("The size of 0 is 1 bytes.", f.Name, f.Length);



        the GetFiles method returns an array of FileInfo objects, where you can find the filesize.



        Parameters:



        I this example i'm writing to console output but in the same way you can add the text to your textbox.



         mytexbox.Text += String.Format("The size of 0 is 1 bytes.rn", f.Name, f.Length);





        share|improve this answer




















          Your Answer





          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51739965%2fc-sharp-get-file-size-of-array-with-paths%23new-answer', 'question_page');

          );

          Post as a guest






























          5 Answers
          5






          active

          oldest

          votes








          5 Answers
          5






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          7
          down vote



          accepted










          If i understand you correctly, just use Linq Select and string.Join



          var results = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories)
          .Select(file => new FileInfo(file).Length);

          TextBox1.Text = string.Join(", ", results);


          if you want to sum them, just use Enumerable.Sum



           TextBox1.Text = $"results.Sum():N3";


          Update



          public static class MyExtension

          public enum SizeUnits

          Byte, KB, MB, GB, TB, PB, EB, ZB, YB


          public static string ToSize(this Int64 value, SizeUnits unit)

          return (value / (double)Math.Pow(1024, (Int64)unit)).ToString("0.00");



          TextBox1.Text = results.Sum().ToSize();





          share|improve this answer






















          • One more question, is there a way to get a decimal value? In my case a file has the size of 14.9 MB but I end up with 14 MB.
            – loyd
            Aug 8 at 8:24






          • 1




            @loyd yes you can use format specifiers. updated
            – TheGeneral
            Aug 8 at 8:26






          • 1




            @loyd you can read more about them here docs.microsoft.com/en-us/dotnet/standard/base-types/…
            – TheGeneral
            Aug 8 at 8:26










          • I used $"results.Sum() / (1024*1024):N3"; to get the file size in MB but the decimal value gets filled with zeros only. What is my mistake?
            – loyd
            Aug 8 at 9:49






          • 1




            @loyd you could use $"results.Sum() / (double)(1024*1024):N3", or i updated my answer if you want to get fancy
            – TheGeneral
            Aug 8 at 9:50















          up vote
          7
          down vote



          accepted










          If i understand you correctly, just use Linq Select and string.Join



          var results = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories)
          .Select(file => new FileInfo(file).Length);

          TextBox1.Text = string.Join(", ", results);


          if you want to sum them, just use Enumerable.Sum



           TextBox1.Text = $"results.Sum():N3";


          Update



          public static class MyExtension

          public enum SizeUnits

          Byte, KB, MB, GB, TB, PB, EB, ZB, YB


          public static string ToSize(this Int64 value, SizeUnits unit)

          return (value / (double)Math.Pow(1024, (Int64)unit)).ToString("0.00");



          TextBox1.Text = results.Sum().ToSize();





          share|improve this answer






















          • One more question, is there a way to get a decimal value? In my case a file has the size of 14.9 MB but I end up with 14 MB.
            – loyd
            Aug 8 at 8:24






          • 1




            @loyd yes you can use format specifiers. updated
            – TheGeneral
            Aug 8 at 8:26






          • 1




            @loyd you can read more about them here docs.microsoft.com/en-us/dotnet/standard/base-types/…
            – TheGeneral
            Aug 8 at 8:26










          • I used $"results.Sum() / (1024*1024):N3"; to get the file size in MB but the decimal value gets filled with zeros only. What is my mistake?
            – loyd
            Aug 8 at 9:49






          • 1




            @loyd you could use $"results.Sum() / (double)(1024*1024):N3", or i updated my answer if you want to get fancy
            – TheGeneral
            Aug 8 at 9:50













          up vote
          7
          down vote



          accepted







          up vote
          7
          down vote



          accepted






          If i understand you correctly, just use Linq Select and string.Join



          var results = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories)
          .Select(file => new FileInfo(file).Length);

          TextBox1.Text = string.Join(", ", results);


          if you want to sum them, just use Enumerable.Sum



           TextBox1.Text = $"results.Sum():N3";


          Update



          public static class MyExtension

          public enum SizeUnits

          Byte, KB, MB, GB, TB, PB, EB, ZB, YB


          public static string ToSize(this Int64 value, SizeUnits unit)

          return (value / (double)Math.Pow(1024, (Int64)unit)).ToString("0.00");



          TextBox1.Text = results.Sum().ToSize();





          share|improve this answer














          If i understand you correctly, just use Linq Select and string.Join



          var results = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories)
          .Select(file => new FileInfo(file).Length);

          TextBox1.Text = string.Join(", ", results);


          if you want to sum them, just use Enumerable.Sum



           TextBox1.Text = $"results.Sum():N3";


          Update



          public static class MyExtension

          public enum SizeUnits

          Byte, KB, MB, GB, TB, PB, EB, ZB, YB


          public static string ToSize(this Int64 value, SizeUnits unit)

          return (value / (double)Math.Pow(1024, (Int64)unit)).ToString("0.00");



          TextBox1.Text = results.Sum().ToSize();






          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Aug 8 at 9:50

























          answered Aug 8 at 6:35









          TheGeneral

          18k52657




          18k52657











          • One more question, is there a way to get a decimal value? In my case a file has the size of 14.9 MB but I end up with 14 MB.
            – loyd
            Aug 8 at 8:24






          • 1




            @loyd yes you can use format specifiers. updated
            – TheGeneral
            Aug 8 at 8:26






          • 1




            @loyd you can read more about them here docs.microsoft.com/en-us/dotnet/standard/base-types/…
            – TheGeneral
            Aug 8 at 8:26










          • I used $"results.Sum() / (1024*1024):N3"; to get the file size in MB but the decimal value gets filled with zeros only. What is my mistake?
            – loyd
            Aug 8 at 9:49






          • 1




            @loyd you could use $"results.Sum() / (double)(1024*1024):N3", or i updated my answer if you want to get fancy
            – TheGeneral
            Aug 8 at 9:50

















          • One more question, is there a way to get a decimal value? In my case a file has the size of 14.9 MB but I end up with 14 MB.
            – loyd
            Aug 8 at 8:24






          • 1




            @loyd yes you can use format specifiers. updated
            – TheGeneral
            Aug 8 at 8:26






          • 1




            @loyd you can read more about them here docs.microsoft.com/en-us/dotnet/standard/base-types/…
            – TheGeneral
            Aug 8 at 8:26










          • I used $"results.Sum() / (1024*1024):N3"; to get the file size in MB but the decimal value gets filled with zeros only. What is my mistake?
            – loyd
            Aug 8 at 9:49






          • 1




            @loyd you could use $"results.Sum() / (double)(1024*1024):N3", or i updated my answer if you want to get fancy
            – TheGeneral
            Aug 8 at 9:50
















          One more question, is there a way to get a decimal value? In my case a file has the size of 14.9 MB but I end up with 14 MB.
          – loyd
          Aug 8 at 8:24




          One more question, is there a way to get a decimal value? In my case a file has the size of 14.9 MB but I end up with 14 MB.
          – loyd
          Aug 8 at 8:24




          1




          1




          @loyd yes you can use format specifiers. updated
          – TheGeneral
          Aug 8 at 8:26




          @loyd yes you can use format specifiers. updated
          – TheGeneral
          Aug 8 at 8:26




          1




          1




          @loyd you can read more about them here docs.microsoft.com/en-us/dotnet/standard/base-types/…
          – TheGeneral
          Aug 8 at 8:26




          @loyd you can read more about them here docs.microsoft.com/en-us/dotnet/standard/base-types/…
          – TheGeneral
          Aug 8 at 8:26












          I used $"results.Sum() / (1024*1024):N3"; to get the file size in MB but the decimal value gets filled with zeros only. What is my mistake?
          – loyd
          Aug 8 at 9:49




          I used $"results.Sum() / (1024*1024):N3"; to get the file size in MB but the decimal value gets filled with zeros only. What is my mistake?
          – loyd
          Aug 8 at 9:49




          1




          1




          @loyd you could use $"results.Sum() / (double)(1024*1024):N3", or i updated my answer if you want to get fancy
          – TheGeneral
          Aug 8 at 9:50





          @loyd you could use $"results.Sum() / (double)(1024*1024):N3", or i updated my answer if you want to get fancy
          – TheGeneral
          Aug 8 at 9:50













          up vote
          2
          down vote













          If you don't want to add complexity by using LINQ and want to practice with arrays:



          var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);

          long length = 0;

          for (int i = 0; i < Files.Length; i++)

          length += new FileInfo(Files[i]).Length;






          share|improve this answer


























            up vote
            2
            down vote













            If you don't want to add complexity by using LINQ and want to practice with arrays:



            var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);

            long length = 0;

            for (int i = 0; i < Files.Length; i++)

            length += new FileInfo(Files[i]).Length;






            share|improve this answer
























              up vote
              2
              down vote










              up vote
              2
              down vote









              If you don't want to add complexity by using LINQ and want to practice with arrays:



              var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);

              long length = 0;

              for (int i = 0; i < Files.Length; i++)

              length += new FileInfo(Files[i]).Length;






              share|improve this answer














              If you don't want to add complexity by using LINQ and want to practice with arrays:



              var Files = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories);

              long length = 0;

              for (int i = 0; i < Files.Length; i++)

              length += new FileInfo(Files[i]).Length;







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Aug 8 at 6:51









              ershoaib

              1,5271412




              1,5271412










              answered Aug 8 at 6:37









              moro91

              14812




              14812




















                  up vote
                  0
                  down vote













                  The below code may work to you.



                  var FilesAndSizes = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories).Select(item => new KeyValuePair<string,int>(item, new System.IO.FileInfo(item).Length));





                  share|improve this answer
























                    up vote
                    0
                    down vote













                    The below code may work to you.



                    var FilesAndSizes = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories).Select(item => new KeyValuePair<string,int>(item, new System.IO.FileInfo(item).Length));





                    share|improve this answer






















                      up vote
                      0
                      down vote










                      up vote
                      0
                      down vote









                      The below code may work to you.



                      var FilesAndSizes = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories).Select(item => new KeyValuePair<string,int>(item, new System.IO.FileInfo(item).Length));





                      share|improve this answer












                      The below code may work to you.



                      var FilesAndSizes = Directory.GetFiles(Path, "*" + filetype, SearchOption.AllDirectories).Select(item => new KeyValuePair<string,int>(item, new System.IO.FileInfo(item).Length));






                      share|improve this answer












                      share|improve this answer



                      share|improve this answer










                      answered Aug 8 at 6:40









                      Ali Rasoulian

                      977




                      977




















                          up vote
                          0
                          down vote













                          Using Directory.EnumerateFiles you're able to calculate the total size while only traversing the array once.



                          To get the total size for all files of an extension:



                          long totalSizeInBytes = 0;
                          foreach(var file in Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories))

                          totalSizeInBytes += new FileInfo(file).Length;



                          To get a list of all file sizes:



                          var results = Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories)
                          .Select(file => new FileInfo(file).Length);

                          TextBox1.Text = string.Join(", ", results);





                          share|improve this answer
























                            up vote
                            0
                            down vote













                            Using Directory.EnumerateFiles you're able to calculate the total size while only traversing the array once.



                            To get the total size for all files of an extension:



                            long totalSizeInBytes = 0;
                            foreach(var file in Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories))

                            totalSizeInBytes += new FileInfo(file).Length;



                            To get a list of all file sizes:



                            var results = Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories)
                            .Select(file => new FileInfo(file).Length);

                            TextBox1.Text = string.Join(", ", results);





                            share|improve this answer






















                              up vote
                              0
                              down vote










                              up vote
                              0
                              down vote









                              Using Directory.EnumerateFiles you're able to calculate the total size while only traversing the array once.



                              To get the total size for all files of an extension:



                              long totalSizeInBytes = 0;
                              foreach(var file in Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories))

                              totalSizeInBytes += new FileInfo(file).Length;



                              To get a list of all file sizes:



                              var results = Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories)
                              .Select(file => new FileInfo(file).Length);

                              TextBox1.Text = string.Join(", ", results);





                              share|improve this answer












                              Using Directory.EnumerateFiles you're able to calculate the total size while only traversing the array once.



                              To get the total size for all files of an extension:



                              long totalSizeInBytes = 0;
                              foreach(var file in Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories))

                              totalSizeInBytes += new FileInfo(file).Length;



                              To get a list of all file sizes:



                              var results = Directory.EnumerateFiles(Path, "*" + filetype, SearchOption.AllDirectories)
                              .Select(file => new FileInfo(file).Length);

                              TextBox1.Text = string.Join(", ", results);






                              share|improve this answer












                              share|improve this answer



                              share|improve this answer










                              answered Aug 8 at 7:11









                              Mel Gerats

                              1,83211230




                              1,83211230




















                                  up vote
                                  0
                                  down vote













                                  i think that DirectoryInfo object cuold be smarter for your case istead of Directory object.



                                  Look at that example:



                                  public static void Main()

                                  string filetype = ".jpg";

                                  // Make a reference to a directory.
                                  DirectoryInfo di = new DirectoryInfo("c:\");
                                  // Get a reference to each file in that directory.
                                  FileInfo fiArr = di.GetFiles("*" + filetype, SearchOption.AllDirectories);
                                  // Display the names and sizes of the files.
                                  Console.WriteLine("The directory 0 contains the following files:", di.Name);
                                  foreach (FileInfo f in fiArr)
                                  Console.WriteLine("The size of 0 is 1 bytes.", f.Name, f.Length);



                                  the GetFiles method returns an array of FileInfo objects, where you can find the filesize.



                                  Parameters:



                                  I this example i'm writing to console output but in the same way you can add the text to your textbox.



                                   mytexbox.Text += String.Format("The size of 0 is 1 bytes.rn", f.Name, f.Length);





                                  share|improve this answer
























                                    up vote
                                    0
                                    down vote













                                    i think that DirectoryInfo object cuold be smarter for your case istead of Directory object.



                                    Look at that example:



                                    public static void Main()

                                    string filetype = ".jpg";

                                    // Make a reference to a directory.
                                    DirectoryInfo di = new DirectoryInfo("c:\");
                                    // Get a reference to each file in that directory.
                                    FileInfo fiArr = di.GetFiles("*" + filetype, SearchOption.AllDirectories);
                                    // Display the names and sizes of the files.
                                    Console.WriteLine("The directory 0 contains the following files:", di.Name);
                                    foreach (FileInfo f in fiArr)
                                    Console.WriteLine("The size of 0 is 1 bytes.", f.Name, f.Length);



                                    the GetFiles method returns an array of FileInfo objects, where you can find the filesize.



                                    Parameters:



                                    I this example i'm writing to console output but in the same way you can add the text to your textbox.



                                     mytexbox.Text += String.Format("The size of 0 is 1 bytes.rn", f.Name, f.Length);





                                    share|improve this answer






















                                      up vote
                                      0
                                      down vote










                                      up vote
                                      0
                                      down vote









                                      i think that DirectoryInfo object cuold be smarter for your case istead of Directory object.



                                      Look at that example:



                                      public static void Main()

                                      string filetype = ".jpg";

                                      // Make a reference to a directory.
                                      DirectoryInfo di = new DirectoryInfo("c:\");
                                      // Get a reference to each file in that directory.
                                      FileInfo fiArr = di.GetFiles("*" + filetype, SearchOption.AllDirectories);
                                      // Display the names and sizes of the files.
                                      Console.WriteLine("The directory 0 contains the following files:", di.Name);
                                      foreach (FileInfo f in fiArr)
                                      Console.WriteLine("The size of 0 is 1 bytes.", f.Name, f.Length);



                                      the GetFiles method returns an array of FileInfo objects, where you can find the filesize.



                                      Parameters:



                                      I this example i'm writing to console output but in the same way you can add the text to your textbox.



                                       mytexbox.Text += String.Format("The size of 0 is 1 bytes.rn", f.Name, f.Length);





                                      share|improve this answer












                                      i think that DirectoryInfo object cuold be smarter for your case istead of Directory object.



                                      Look at that example:



                                      public static void Main()

                                      string filetype = ".jpg";

                                      // Make a reference to a directory.
                                      DirectoryInfo di = new DirectoryInfo("c:\");
                                      // Get a reference to each file in that directory.
                                      FileInfo fiArr = di.GetFiles("*" + filetype, SearchOption.AllDirectories);
                                      // Display the names and sizes of the files.
                                      Console.WriteLine("The directory 0 contains the following files:", di.Name);
                                      foreach (FileInfo f in fiArr)
                                      Console.WriteLine("The size of 0 is 1 bytes.", f.Name, f.Length);



                                      the GetFiles method returns an array of FileInfo objects, where you can find the filesize.



                                      Parameters:



                                      I this example i'm writing to console output but in the same way you can add the text to your textbox.



                                       mytexbox.Text += String.Format("The size of 0 is 1 bytes.rn", f.Name, f.Length);






                                      share|improve this answer












                                      share|improve this answer



                                      share|improve this answer










                                      answered Aug 8 at 7:13









                                      Danilo Calzetta

                                      1,134623




                                      1,134623



























                                           

                                          draft saved


                                          draft discarded















































                                           


                                          draft saved


                                          draft discarded














                                          StackExchange.ready(
                                          function ()
                                          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f51739965%2fc-sharp-get-file-size-of-array-with-paths%23new-answer', 'question_page');

                                          );

                                          Post as a guest













































































                                          Comments

                                          Popular posts from this blog

                                          What does second last employer means? [closed]

                                          List of Gilmore Girls characters

                                          Confectionery