G120 and more then 63 files in a folder

I have a problem with not be able to create more then 63 files in a folder.

There is no problem with creating the files above numer 63, but they do not exist.
I can write to them , but not open them later for reading in NETMF.

As long as I delete a file in folder so I have max 62 files I can create, write and read the file.


In a folder or the root? Did you try a different drive? Did you format?

In second subfolder,
tried different SD cards, yes formated.

We will test on our end

I had a problem when using FAT formated cards. You can only put 256 files into one folder. FAT32 solved this.

I know that 63 is not 256, but you might try different formats and see if that helps.

I had the same Problem with a log file funtion (also G120).
I could create only 3 files in that folder with my code.
I then delted the files, but after 3 files the 4ths was not there again (no Errors on writing).
I think that this had something to do that the files where not really/fully written to SD Card before I made a reset (I kept the file open und used flush on the TextWriter stream).
Then I changed my code to open and Close the file every time, and this Problem was solved.
But then it was so slow that I had to disable file logging fully (for now)

@ Honken - Are you disposing previously used handles properly? It can be a coding issue. Can you show your code please?

I ran a test on the G120, using the currently available firmware, and was able to create 279 files. This is where I stopped letting it run. Please run this code on your device to see if you still have an issue.

Last output:

Creating file #279
Writing out to file
Verifying file
Verification complete

File279.txt -- This is file #279

using System;
using System.Collections;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Presentation;
using Microsoft.SPOT.Presentation.Controls;
using Microsoft.SPOT.Presentation.Media;
using Microsoft.SPOT.Presentation.Shapes;
using Microsoft.SPOT.Touch;

using Gadgeteer.Networking;
using GT = Gadgeteer;
using GTM = Gadgeteer.Modules;
using Microsoft.SPOT.IO;
using GHI.Premium.IO;
using System.IO;

namespace Topic_13912
    public partial class Program
        PersistentStorage sd;

        // This method is run when the mainboard is powered up or reset.   
        void ProgramStarted()
            Modules added in the Program.gadgeteer designer view are used by typing 
            their name followed by a period, e.g.  button.  or  camera.
            Many modules generate useful events. Type +=<tab><tab> to add a handler to an event, e.g.:
                button.ButtonPressed +=<tab><tab>
            If you want to do something periodically, use a GT.Timer and handle its Tick event, e.g.:
                GT.Timer timer = new GT.Timer(1000); // every second (1000ms)
                timer.Tick +=<tab><tab>

            // Use Debug.Print to show messages in Visual Studio's "Output" window during debugging.
            Debug.Print("Program Started");


        private void RemovableMedia_Insert()
            Debug.Print("Insert event");

                sd = new PersistentStorage("SD");
                int file = 0;

                while (true)

                    string outName = "File";

                    if (file < 10)
                        outName += "00" + file.ToString() + ".txt";
                    else if (file < 100)
                        outName += "0" + file.ToString() + ".txt";
                        outName += file.ToString() + ".txt";

                    Debug.Print("Creating file #" + file.ToString());
                    FileStream outstream = new FileStream("SD\\subfolder\\" + outName, FileMode.Create);

                    Debug.Print("Writing out to file");

                    string outtext = "This is file #" + file.ToString();
                    outstream.Write(System.Text.Encoding.UTF8.GetBytes(outtext), 0, outtext.Length);

                    Debug.Print("Verifying file");
                    byte[] inbuffer = new byte[outtext.Length];

                    FileStream instream = new FileStream("SD\\subfolder\\" + outName, FileMode.Open);

                    int read = instream.Read(inbuffer, 0, outtext.Length);

                    if (read != outtext.Length)
                        Debug.Print("Length incorrect on file #" + file.ToString());


                    string instring = new string(System.Text.Encoding.UTF8.GetChars(inbuffer));

                    if (instring != outtext)

                        Debug.Print("Byte mismatch on file #" + file.ToString());


                    Debug.Print("Verification complete");

            catch (Exception error)


@ James -
you code:


is it really required to use both?

Close Method:
Closes the current stream and releases any resources (such as sockets and file handles) associated with the current stream. Instead of calling this method, ensure that the stream is properly disposed.

this might be of interest : http://msdn.microsoft.com/en-us/library/vstudio/yh598w02.aspx

It is not strict;y required, as I believe the implementation of dispose should call any methods such as close that a class requires before a destruction. Placement of both lines is purely habitual .

With Jame’s code, it works fine for me, these SD below were tested:

  • SDHC 8G class 10
  • SDHC 16G class 10
  • MicroSD 2G with FAT32 format
  • Kington 2G
  • MMC 256MB

I have tested it and the code works fine as for you others.

I think as soon as you got a corrupt file in a path/folder that stops for creating new files.
I looks like the new file is created but no no.

@ Honken - Thanks for sharing!