Listing files and folders on the sd card w/ ctrulib

Discussion in '3DS - Homebrew Development and Emulators' started by PrintHello, Sep 25, 2016.

  1. PrintHello
    OP

    PrintHello Member

    Newcomer
    37
    15
    Feb 10, 2016
    So I'm trying to write a simple text editor for the 3ds using ctrulib, sf2dlib, etc... and I've hit upon a snag.

    What I'm trying to do is list all of the files and folders in a directory on the SD card, and I've seen many examples of where people do this on github, but they all seem to require me to use an older version of ctrulib as in the version I have (latest release I believe) the FS_Archive type is a simple u64 rather than a struct of {FS_ArchiveID someID ,FS_Path somePath} or something of the sort.

    Not sure if this is just me not understanding properly how C++/ctrulib works or if there is something I'm missing or what.

    Here is the code I have currently:
    Warning: Spoilers inside!

    Now, the strange thing is, when I run my program in Citra, I get an output of all the files and folders in the /sdmc/ directory, whereas running on my 3ds I get no output, the program doesn't crash, but I don't get any output to the console past "Tried to read Directory".

    ¯\_(ツ)_/¯

    Any help is appreciated and thanks for taking the time to stop by
     
  2. JK_

    JK_ GBAtemp Fan

    Member
    377
    692
    Sep 4, 2015
    United States
    Try changing this line:
    Code:
    FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, dirPath);
    
    To this:
    Code:
    FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
    
     
  3. PrintHello
    OP

    PrintHello Member

    Newcomer
    37
    15
    Feb 10, 2016
    :grog: worked perfectly haha. So say if I wanted to go into a different directory, i would use (PATH_ASCII,"/3ds/") to go into the /3ds/ directory right?

    Edit: I did actually try that except rather than putting "" as the 2nd argument I put NULL, which it didn't like so I gave up on that, guess I shouldn't be so quick at dismissing possible solutions.
     
    Last edited by PrintHello, Sep 25, 2016
  4. JK_

    JK_ GBAtemp Fan

    Member
    377
    692
    Sep 4, 2015
    United States
    You'd change the dirPath to point to '/3ds/'. Opening the sdmc archive requires an empty archive path.
     
  5. PrintHello
    OP

    PrintHello Member

    Newcomer
    37
    15
    Feb 10, 2016
    Oh I understand, thanks :)