Accessing SD file size in bytes

Can anyone provide some quick guidance on accessing file size in bytes from an SD card? I’ve searched the forum and .NET references, but seem to be stuck. I can use “.length” to count the number of files, but seem to be a bit thick headed about how to access file size (I am new to C# and .NET). At the risk of showing further ignorance here’s a code snippet with output. Obviously I’ve also not seen how to post code properly. Thanks for any help.

string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
string[] files = Directory.GetFiles(rootDirectory);
long filesize = new FileInfo(rootDirectory).Length;
string[] folders = Directory.GetDirectories(rootDirectory);
Debug.Print("Files available on " + rootDirectory + “:”) ;
Debug.Print("length = " + filesize.ToString());
for (int m = 0; m < files.Length; m++)
Debug.Print(files[m] + " " + files.Length.ToString());

**************** OUTPUT *****************

Files available on \SD:
length = 0
\SD\Temperatures_2.csv 5
\SD\ADS_4000_README.txt 5
\SD\Temperatures_3.csv 5
\SD\Temperatures_1.csv 5
\SD\Temperatures.csv 5
Folders available on \SD:
\SD\test folder 1
\SD\test folder 2

use binary button (with 0’s and 1’s) in the toolbar:


string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
string[] files = Directory.GetFiles(rootDirectory);
long filesize = new FileInfo(rootDirectory).Length;
string[] folders = Directory.GetDirectories(rootDirectory);
Debug.Print("Files available on " + rootDirectory + ":"  ;
Debug.Print("length = " + filesize.ToString());
for (int m = 0; m < files.Length; m++)
Debug.Print(files[m] + " " + files.Length.ToString());

Try this code instead:


            string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
            string[] files = Directory.GetFiles(rootDirectory);
            long filesize = new FileInfo(rootDirectory).Length;
            string[] folders = Directory.GetDirectories(rootDirectory);
            Debug.Print("Files available on " + rootDirectory + ":");
            Debug.Print("length = " + files.Length.ToString());
            for (int m = 0; m < files.Length; m++)
            {
                FileInfo fi=new FileInfo(files[m]);
                Debug.Print(files[m] + " " + fi.Length.ToString());
            }

Thanks, Architect. When I hit this reply I now see the binary icon. For some odd reason when I sent the original post I did not have the first five icons showing on my desktop - no idea why. It was my desktop PC, but that shouldn’t have made any difference. I’ll go back and see if I can duplicate that later.

I am reposting the code to make sure I know how it’s done.

                                    string rootDirectory = VolumeInfo.GetVolumes()[0].RootDirectory;
string[] files = Directory.GetFiles(rootDirectory);
long filesize = new FileInfo(rootDirectory).Length;
string[] folders = Directory.GetDirectories(rootDirectory);
Debug.Print("Files available on " + rootDirectory + ":");
Debug.Print("length = " + filesize.ToString());
for (int m = 0; m < files.Length; m++)
Debug.Print(files[m] + "   " + files.Length.ToString());  //trying tp print file size but prints the number of files
Debug.Print("Folders available on " + rootDirectory + ":");
for (int m = 0; m < folders.Length; m++)
 Debug.Print(folders[m]);

Thanks again Architect, you suggested code worked just fine. I will study it further to be sure I’ve learned.

All this help is appreciated and speeding the progress. Not where I need to be yet, however, so I’m sure I’ll have more questions later.

you are welcome! Let me know if you have questions