Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

SD Card create directory


  • Please log in to reply
6 replies to this topic

#1 Ferocildo

Ferocildo

    New Member

  • Members
  • Pip
  • 9 posts

Posted 21 June 2012 - 05:17 PM

Hello, I can write files to the SD\ root but can't manage to create directories.. I tried to use Directory.SetCurrentDirectory("SD"); Directory.CreateDirectory("Netduino"); as in http://www.dyadica.c...d-card-example/ but nothing happens.. also tried to put the new directory in the filename while creating a filestream but i get exception.

#2 Robert L.

Robert L.

    Advanced Member

  • Members
  • PipPipPip
  • 100 posts

Posted 21 June 2012 - 11:27 PM

Hello,

I can write files to the SD\ root but can't manage to create directories..

I tried to use

Directory.SetCurrentDirectory("SD");
Directory.CreateDirectory("Netduino");

as in http://www.dyadica.c...d-card-example/

but nothing happens..

also tried to put the new directory in the filename while creating a filestream but i get exception.



I just tried the following one line of code with one of my boards. I am running version 4.2.0.0 RC4. The directory was successfully created, verified by mounting the SD card as a drive on my PC.

Directory.CreateDirectory(@"\SD\Netduino");

Perhaps you need a "\" before the "SD" ? Or perhaps you are using an older version of the OS ? In any case the above works on my N+.

#3 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 22 June 2012 - 03:25 AM

Hi Ferocildo, Also, this may sound odd but...try formatting the SD card and see if CreateDirectory then works for you. Some SD cards come with unusual formatting. Chris

#4 Ferocildo

Ferocildo

    New Member

  • Members
  • Pip
  • 9 posts

Posted 26 June 2012 - 12:31 PM

I just tried the Directory.CreateDirectory(@"\SD\Netduino"); line code alone, but nothing happens. I've also tried formatting by Windows7 with FAT32 my 2GB SD card. Maybe I'll try buying another sd card, however writing of files is working, so that's strange

#5 Ferocildo

Ferocildo

    New Member

  • Members
  • Pip
  • 9 posts

Posted 30 August 2012 - 09:38 AM

the following code create all directories but the last! why?

using System;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.IO;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.NetduinoPlus;
//using LoveElectronics.Sensors.Accelerometers;

namespace ADXL345_test
{
    public class Program
    {
        private static StreamWriter sw;
        private static FileStream fs;

        public static void Main()
        {
            OutputPort led = new OutputPort(Pins.ONBOARD_LED, false);
            InputPort Switch1 = new InputPort(Pins.ONBOARD_SW1, true, Port.ResistorMode.Disabled);

            while (!Switch1.Read())
            {}

            led.Write(true);

            Directory.CreateDirectory(@"SD\Netduino");

            fs = new FileStream(@"SD\Netduino\test.txt", FileMode.Create, FileAccess.Write, FileShare.None, 512);

            Directory.CreateDirectory(@"SD\Netduino1");

            sw = new StreamWriter(fs);

            Directory.CreateDirectory(@"\SD\Netduino2");
            sw.WriteLine("test");

            Directory.CreateDirectory(@"\SD\Netduino3");
            sw.Close();

            Directory.CreateDirectory(@"\SD\Netduino4");
            fs.Close();

            Directory.CreateDirectory(@"\SD\Netduino5");

        }

    }
}


#6 nakchak

nakchak

    Advanced Member

  • Members
  • PipPipPip
  • 404 posts
  • LocationBristol, UK

Posted 30 August 2012 - 10:05 AM

You are closing the FileStream before you call the last create directory statement, that might have something to do with it... What happens when you have all of your create directory statements together instead of mixed in between a file write? Also some of your create directory calls have a leading "\" some don't, try and make your calls more consistent as it will be easier to work out what is going on Nak.

#7 JerseyTechGuy

JerseyTechGuy

    Advanced Member

  • Members
  • PipPipPip
  • 870 posts

Posted 30 August 2012 - 01:40 PM

There are some code inconsistencies. Clean up the code and perhaps put a Thread.Sleep(1) between each call to give it time to catch up. Just for code cleanliness purposes and ease of debugging suggest you close everything before the end of the code not in-between the createdirectory calls.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.