Homebrew Listing files and folders on the sd card w/ ctrulib

PrintHello

Active Member
OP
Newcomer
Joined
Feb 10, 2016
Messages
37
Trophies
0
Age
28
XP
149
Country
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:
Code:
void tryReadDir(){
    //Mostly copied from lpp-3ds, and edited a lil

    Handle dirHandle;
    FS_DirectoryEntry entry;

    //Make a path object from the path string
    const char *path = "/";
    FS_Path dirPath = fsMakePath(PATH_ASCII, path);

    //Create an archive object
    FS_Archive sdmcArchive;

    //Open the SD card into the archive object
    FSUSER_OpenArchive( &sdmcArchive, ARCHIVE_SDMC, dirPath);

    //Get a directory from the SD card archive ('/' in this case)
    FSUSER_OpenDirectory(&dirHandle, sdmcArchive, dirPath);

    //Init some vars for storing directory listing data
    u32 entriesRead;
    static char name[1024];

    //Debug to show the function has gone this far
    sConsole.appendLine("Tried to read Directory");
    for (;;){

            //Reset entries var
            entriesRead=0;

            //Read the next item in the directory
            FSDIR_Read(dirHandle, &entriesRead, 1, (FS_DirectoryEntry*)&entry);

            //If there is a next item
            if (entriesRead){
                //also from lpp-3ds, converts a utf-8 to a string
                utf2ascii(&name[0], entry.name);

                //Debug, prints file/folder name to console
                sConsole.appendLine(std::string(name));
            }else break;
    }
    //Close handles and archives.
    FSDIR_Close(dirHandle);
    svcCloseHandle(dirHandle);
    FSUSER_CloseArchive(sdmcArchive);
}

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
 

JK_

Well-Known Member
Member
Joined
Sep 4, 2015
Messages
694
Trophies
1
XP
2,289
Country
United States
Try changing this line:
Code:
FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, dirPath);
To this:
Code:
FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));
 

PrintHello

Active Member
OP
Newcomer
Joined
Feb 10, 2016
Messages
37
Trophies
0
Age
28
XP
149
Country
Try changing this line:
Code:
FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, dirPath);
To this:
Code:
FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, fsMakePath(PATH_EMPTY, ""));

: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,

JK_

Well-Known Member
Member
Joined
Sep 4, 2015
Messages
694
Trophies
1
XP
2,289
Country
United States
: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
You'd change the dirPath to point to '/3ds/'. Opening the sdmc archive requires an empty archive path.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    Psionic Roshambo @ Psionic Roshambo: I am the cancer!!! lol