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
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]);