I am using an SC20260E in a data collection system and I have run into an issue where I cannot write more than 400 files to an SD card. I am using a 32GB card, formatted FAT 32. When I try to write another file after 400, I see the following exception:
#### Exception System.InvalidOperationException - CLR_E_INVALID_OPERATION (1) ####
#### Message:
#### GHIElectronics.TinyCLR.IO.FileSystem+NativeFileStream::Write [IP: 0000] ####
#### System.IO.FileStream::Write [IP: 0041] ####
Does anybody else experience the same?
How about each folder 100 files?
Anyway, just quick test, write 500 files looks till good to us:
Simple code below:
static void DoTestWrite500()
{
var systemTimeStart = DateTime.Now;
var media = StorageController.FromName(FSSD_API_CONTROLLER);
var drive = GHIElectronics.TinyCLR.IO.FileSystem.Mount(media.Hdc);
DriveInfo driveInfo = new DriveInfo(drive.Name);
Debug.WriteLine("Free: " + driveInfo.TotalFreeSpace);
Debug.WriteLine("TotalSize: " + driveInfo.TotalSize);
Debug.WriteLine("VolumeLabel:" + driveInfo.VolumeLabel);
Debug.WriteLine("RootDirectory: " + driveInfo.RootDirectory);
Debug.WriteLine("DriveFormat: " + driveInfo.DriveFormat);
for (int i = 0; i < 500; i++)
{
var filename = drive.Name + "\\test" + i.ToString() + ".txt";
using (var writeStrem = File.Open(filename, FileMode.Create))
{
var data = System.Text.Encoding.UTF8.GetBytes("Thi is for test\n");
writeStrem.Write(data, 0, data.Length);
writeStrem.Flush();
}
Thread.Sleep(10);
Debug.WriteLine("done write " + filename);
}
GHIElectronics.TinyCLR.IO.FileSystem.Flush(media.Hdc);
}
Your code ran fine on my system as well, definitely odd as I am able to recreate my issue as well. I found a limit of 128 files per folder, I am limiting my directory size to 120 because of that.
You mentioned 100 files per folder, is that something I should consider a limit instead?
i am seeing the speed of writting slow down when write from files 3xx if they are same folder.