I am running a program in a G30. I need to list the files in a SD directory, but when the directory has more than 50 files I got an OutOfMemory exception.
I am using an example program from MSDN site that creates a string[] and loads it with all the filenames from the directory, and most probably that is reason for the OutOfMemory exception, but I don’t know another way to do it.
Any ideas to list the files one by one?
This is the code I am using:
public static void Dir(string dir)
{
string path = "";
if (dir.Length > 0) path = VolumeInfo.GetVolumes()[0].RootDirectory + @ "\" + dir + @ "\";
else path = VolumeInfo.GetVolumes()[0].RootDirectory + @ "\";
string[] dirPaths = Directory.GetDirectories(path);
int k;
for (k = 0; k < dirPaths.Length; k++)
{
Debug.Print(dirPaths[k].Substring(4).ToUpper() + @ "\");
}
// Here is where I get OutOfMemory condition
string[] filePaths = Directory.GetFiles(path);
for (k = 0; k < filePaths.Length; k++)
{
Debug.Print(filePaths[k].Substring(4).ToUpper());
}
}