Les membres ayant 30 points peuvent parler sur les canaux annonces, projets et hs du chat.
La shoutbox n'est pas chargée par défaut pour des raisons de performances. Cliquez pour charger.

Forum Casio - Autres questions


Index du Forum » Autres questions » how to listdir in gint ?
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

how to listdir in gint ?

Posté le 12/12/2023 17:34

In the beginning, I thank Lephenixnoir for introducing Gint and FxSDK. It made it very easy for me. So far, I have no problems dealing with it. I want to know how I can access the file names located in the current path. We will assume that the current path is registered inside (PATH).
uint16_t PATH = u"////fls0//";


How can I write a function to do this?
I tried asking ChatGPT and it gave me this function

void listdir(uint16_t const *path , list_t* scr, int x_scrl ,int y_scrl) {
    void listdir(uint16_t const *path) {
    int shandle;
    uint16_t foundfile[FILENAME_MAX];
    struct BFile_FileInfo fileinfo;

    // Open a search handle
    int result = BFile_FindFirst(path, &shandle, foundfile, &fileinfo);

    if (result < 0) {
        print_txt(scr,"Error opening directory", x_scrl, y_scrl);
        return;
    }

    // Iterate through the directory entries
    while (result == 0 || result == BFile_EnumerateEnd) {
        print_txt(scr, "F", x_scrl, y_scrl);

        // Continue the search
        result = BFile_FindNext(shandle, foundfile, &fileinfo);

        if (result < 0) {
            print_txt(scr, "Error during enumeration", x_scrl, y_scrl);
            break;
        }
    }

    // Close the search handle
    BFile_FindClose(shandle);
    scroll(scr,x_scrl,y_scrl);
}
}


But it always prints me "Error opening directory", and that
print_txt(scr, ... , x_scrl, y_scrl)
is just something I wrote previously to print a line on the terminal program for the addin.


1, 2 Suivante
Lephenixnoir Hors ligne Administrateur Points: 24581 Défis: 170 Message

Citer : Posté le 12/12/2023 20:48 | #


If you're targeting the fx-CG or the G-III series of black-and-white calcs, you can use the standard functions opendir() and readdir() as they are currently supported by gint and forget about BFile's atrocities.

Otherwise, you can use gint's implementation of opendir(), which lists a directory pretty much as you're trying to do here, as a reference. I'll just go through the code you have currently to try and help a bit more.

First of all, and most importantly, the path is called \\fls0\*. The prefix \\fls0 indicates the storage memory. \ is the folder separator (like in Windows), and you have to specify * to indicate that you want to match all files. Also because this is C, all backslashes need to be doubled because it's the escape character. Finally, note that PATH is a pointer to a sequence of uint16_t, not one of them.

uint16_t *path = u"\\\\fls0\\*";

Then:
int result = BFile_FindFirst(path, &shandle, foundfile, &fileinfo);

Looks good to me.

while (result == 0 || result == BFile_EnumerateEnd) {

You should certainly stop the loop at BFile_EnumerateEnd.

Finally, while the find functions have generally been shown to work while using gint, you should world switch out of gint to use them.

Nitpick: no idea where that nested function is coming from but it probably shouldn't be there.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 12/12/2023 21:12 | #


Lephenixnoir a écrit :
If you're targeting the fx-CG or the G-III series of black-and-white calcs, you can use the standard functions opendir() and readdir() as they are currently supported by gint and forget about BFile's atrocities.

Otherwise, you can use gint's implementation of opendir(), which lists a directory pretty much as you're trying to do here, as a reference. I'll just go through the code you have currently to try and help a bit more.

First of all, and most importantly, the path is called \\fls0\*. The prefix \\fls0 indicates the storage memory. \ is the folder separator (like in Windows), and you have to specify * to indicate that you want to match all files. Also because this is C, all backslashes need to be doubled because it's the escape character. Finally, note that PATH is a pointer to a sequence of uint16_t, not one of them.

uint16_t *path = u"\\\\fls0\\*";

Then:
int result = BFile_FindFirst(path, &shandle, foundfile, &fileinfo);

Looks good to me.

while (result == 0 || result == BFile_EnumerateEnd) {

You should certainly stop the loop at BFile_EnumerateEnd.

Finally, while the find functions have generally been shown to work while using gint, you should world switch out of gint to use them.

Nitpick: no idea where that nested function is coming from but it probably shouldn't be there.



Thanks buddy, but how i should include them? (dir_t , fugue_dir_explore) , something like ?
#include<gint/fs.h>
Lephenixnoir Hors ligne Administrateur Points: 24581 Défis: 170 Message

Citer : Posté le 12/12/2023 21:17 | #


You can't use fugue_dir_explore directly because it's an internal function, unfortunately... you can get opendir(), readdir() etc. with #include <dirent.h> if that's what you're targeting, otherwise you should copy the code I linked you over to your project and adjust it to fit your needs.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 12/12/2023 21:50 | #


Lephenixnoir a écrit :
You can't use fugue_dir_explore directly because it's an internal function, unfortunately... you can get opendir(), readdir() etc. with #include <dirent.h> if that's what you're targeting, otherwise you should copy the code I linked you over to your project and adjust it to fit your needs.


I apologize for bothering you with my many questions, but this is my first time writing a project in C. I am trying to make a Linux simulator.
All of these functions do not give me output, even though I set the path to
////fls0//


I think tired Python programmers like me have big problems with this
When I am free, I will develop a program to write addin in Python, based on FxSDK
Dimartino Hors ligne Maître du Puzzle Points: 325 Défis: 2 Message

Citer : Posté le 12/12/2023 22:08 | #


If you could make it possible to program addins in Python, that would be really incredible !

The syntax is so much simpler than that of C
Mon projet du moment : Memen'Casio
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 12/12/2023 22:09 | #


Lephenixnoir a écrit :
You can't use fugue_dir_explore directly because it's an internal function, unfortunately... you can get opendir(), readdir() etc. with #include <dirent.h> if that's what you're targeting, otherwise you should copy the code I linked you over to your project and adjust it to fit your needs.


Until now, I have problems with everything related to files and dirs. I don’t know what to do. Do you have documents, courses, or anything in which these things are explained?
Fcalva Hors ligne Membre Points: 600 Défis: 10 Message

Citer : Posté le 12/12/2023 22:11 | #


Dimartino a écrit :
If you could make it possible to program addins in Python, that would be really incredible !

The syntax is so much simpler than that of C


You can already try to scrap something together with a Python -> C compiler if you think it's that great
As for myself i think the benefits wouldn't really be there, and it would dissuade people from trying to pick up C (Unless it's really unpratical )
Pc master race - Apréciateur de Noctua moyen
Caltos : G35+EII, G90+E (briquée )
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 12/12/2023 22:12 | #


Dimartino a écrit :
If you could make it possible to program addins in Python, that would be really incredible !

The syntax is so much simpler than that of C


It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 12/12/2023 22:14 | #


Fcalva a écrit :

You can already try to scrap something together with a Python -> C compiler if you think it's that great
As for myself i think the benefits wouldn't really be there, and it would dissuade people from trying to pick up C (Unless it's really unpratical )


It would actually be impractical because it is simple. I'm tormented now to write a simple program in C
Fcalva Hors ligne Membre Points: 600 Défis: 10 Message

Citer : Posté le 12/12/2023 22:15 | #


Zaky202 a écrit :

Until now, I have problems with everything related to files and dirs. I don’t know what to do. Do you have documents, courses, or anything in which these things are explained?

For those kinds of things you would be better off starting on PC, as - especially on Unix systems - it is much more documented and explained
Zaky202 a écrit :

It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.

I didn't look that much into it, but it seems like the better (and more realistic) approach would be doing a tool that wraps something like Cython with the FxSDK
Edit : To explain more, running python inside of C would be much more complex as the cypthon project shows...
Pc master race - Apréciateur de Noctua moyen
Caltos : G35+EII, G90+E (briquée )
Dimartino Hors ligne Maître du Puzzle Points: 325 Défis: 2 Message

Citer : Posté le 12/12/2023 22:15 | #


If t
Zaky202 a écrit :
Dimartino a écrit :
If you could make it possible to program addins in Python, that would be really incredible !

The syntax is so much simpler than that of C


It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.


If that's what you call simple
Mon projet du moment : Memen'Casio
Lephenixnoir Hors ligne Administrateur Points: 24581 Défis: 170 Message

Citer : Posté le 12/12/2023 22:21 | #


Wait people don't go on tangents about binding Python and C... it's harder than it looks. One thing at a time.

Zaky202 a écrit :
I apologize for bothering you with my many questions, but this is my first time writing a project in C. I am trying to make a Linux simulator.
All of these functions do not give me output, even though I set the path to
////fls0//

Don't worry, do ask! Your path is not correct yet. Paths in the calculator filesystem use backslash (\) as the separator, not slash (/). The path should be u"\\\\fls0\\*" for the search.
Mon graphe (11 Avril): ((Rogue Life || HH2) ; PythonExtra ; serial gint ; Boson X ; passe gint 3 ; ...) || (shoutbox v5 ; v5)
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 12/12/2023 22:21 | #


Dimartino a écrit :
If t
Zaky202 a écrit :
Dimartino a écrit :
If you could make it possible to program addins in Python, that would be really incredible !

The syntax is so much simpler than that of C


It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.


If that's what you call simple


Most of the program will be based on Python, so I am proficient in that. I will look for someone to help me in C only
Fcalva Hors ligne Membre Points: 600 Défis: 10 Message

Citer : Posté le 12/12/2023 22:23 | #


Zaky202 a écrit :

Most of the program will be based on Python, so I am proficient in that. I will look for someone to help me in C only

Please clean up those quotes
Pc master race - Apréciateur de Noctua moyen
Caltos : G35+EII, G90+E (briquée )
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 12/12/2023 22:25 | #


Lephenixnoir a écrit :
Wait people don't go on tangents about binding Python and C... it's harder than it looks. One thing at a time.

Zaky202 a écrit :
I apologize for bothering you with my many questions, but this is my first time writing a project in C. I am trying to make a Linux simulator.
All of these functions do not give me output, even though I set the path to
////fls0//

Don't worry, do ask! Your path is not correct yet. Paths in the calculator filesystem use backslash (\) as the separator, not slash (/). The path should be u"\\\\fls0\\*" for the search.



I tried all of this

char PWD[] = "\\\\fls0\\*";

void listdir(const char* path, list_t* scr, int x_scrl ,int y_scrl) {
    // Explore the directory
    void* dir_data = fugue_dir_explore(path);
    if (!dir_data) {
        print_txt(scr,"Error exploring directory",x_scrl,y_scrl);
        return;
    }

    // Cast the directory data to dir_t
    dir_t* dp = (dir_t*)dir_data;

    // Print the list of files
    for (int i = 0; i < dp->count; i++) {
        print_txt(scr, dp->entries[i]->d_name, x_scrl,y_scrl);
    }

    // Close the directory
    fugue_dir_close(dir_data);
}



else if (strcmp(last_line,"ls") == 0) {
                listdir(PWD,scr,x_scrl,y_scrl);
            }


also


listdir("\\\\fls0",scr,x_scrl,y_scrl);
listdir("\\\\fls0\\",scr,x_scrl,y_scrl);
listdir("\\\\fls0\\*",scr,x_scrl,y_scrl);
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 12/12/2023 22:28 | #


Fcalva a écrit :
Zaky202 a écrit :

Most of the program will be based on Python, so I am proficient in that. I will look for someone to help me in C only

Please clean up those quotes



Potter360 Hors ligne Rédacteur Points: 1254 Défis: 2 Message

Citer : Posté le 12/12/2023 23:07 | #


Zaky202 a écrit :
It's very easy, just to rewrite the gint function in a simple way for Python (C Function). Then I will create a library in pip that deals with FxSDK and writes Python code inside a C file and runs it with Python.h (Python C API) with some additions that you do automatically.


welll i don't think it's that simple... python.h is not officially supported in gint, maybe you will have to deal with some parts of the Python C API (recode some parts of it, adapte it) and, tbh, i don't think this is really easy x)

But if you're really motivated that would be an amazing project ! I personally think that C>Python for, well, a bunch of reasons, but yeah it would be a very nice-engineered system, and maybe it could bring a lot of people that would'nt usually create add-ins to do so... so, good luck !
Globalement, coder. Mal, mais coder.
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 13/12/2023 04:33 | #


Potter360 a écrit :

welll i don't think it's that simple... python.h is not officially supported in gint, maybe you will have to deal with some parts of the Python C API (recode some parts of it, adapte it) and, tbh, i don't think this is really easy x)

But if you're really motivated that would be an amazing project ! I personally think that C>Python for, well, a bunch of reasons, but yeah it would be a very nice-engineered system, and maybe it could bring a lot of people that would'nt usually create add-ins to do so... so, good luck !


Dude, I won't need that. gint is a standalone library. I think the topic depends on my skill in building C (that i don't have now) . I think I can attach it by adding some code to the CMakeLists.txt file. I don't know. I'll try it later.
Potter360 Hors ligne Rédacteur Points: 1254 Défis: 2 Message

Citer : Posté le 13/12/2023 11:32 | #


Yeah but you'll have to recompile Python for the casio calculator... for now Python is just a bunch of code built into a library and compiled for your personal processor - you have to compile it for the casio calculator, which I think , is not really simple.

But anyways, we’re doing kind of off-topic x)
Globalement, coder. Mal, mais coder.
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

Citer : Posté le 13/12/2023 12:32 | #


Potter360 a écrit :
Yeah but you'll have to recompile Python for the casio calculator... for now Python is just a bunch of code built into a library and compiled for your personal processor - you have to compile it for the casio calculator, which I think , is not really simple.

But anyways, we’re doing kind of off-topic x)


I will use the same method for normal FxSDK Addin and link it to the source files on my system and convert it to an extension with ease. I do not know if this will work.
1, 2 Suivante

LienAjouter une imageAjouter une vidéoAjouter un lien vers un profilAjouter du codeCiterAjouter un spoiler(texte affichable/masquable par un clic)Ajouter une barre de progressionItaliqueGrasSoulignéAfficher du texte barréCentréJustifiéPlus petitPlus grandPlus de smileys !
Cliquez pour épingler Cliquez pour détacher Cliquez pour fermer
Alignement de l'image: Redimensionnement de l'image (en pixel):
Afficher la liste des membres
:bow: :cool: :good: :love: ^^
:omg: :fusil: :aie: :argh: :mdr:
:boulet2: :thx: :champ: :whistle: :bounce:
valider
 :)  ;)  :D  :p
 :lol:  8)  :(  :@
 0_0  :oops:  :grr:  :E
 :O  :sry:  :mmm:  :waza:
 :'(  :here:  ^^  >:)

Σ π θ ± α β γ δ Δ σ λ
Veuillez donner la réponse en chiffre
Vous devez activer le Javascript dans votre navigateur pour pouvoir valider ce formulaire.

Si vous n'avez pas volontairement désactivé cette fonctionnalité de votre navigateur, il s'agit probablement d'un bug : contactez l'équipe de Planète Casio.

Planète Casio v4.3 © créé par Neuronix et Muelsaco 2004 - 2024 | Il y a 74 connectés | Nous contacter | Qui sommes-nous ? | Licences et remerciements

Planète Casio est un site communautaire non affilié à Casio. Toute reproduction de Planète Casio, même partielle, est interdite.
Les programmes et autres publications présentes sur Planète Casio restent la propriété de leurs auteurs et peuvent être soumis à des licences ou copyrights.
CASIO est une marque déposée par CASIO Computer Co., Ltd