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.


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.
Fcalva En ligne Membre Points: 521 Défis: 9 Message

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


You should probably make a new topic about that
Pc master race - Apréciateur de Noctua moyen
Caltos : G90+E, FX-92+ (x2)
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

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


Fcalva a écrit :
You should probably make a new topic about that


Maybe Later
Lephenixnoir Hors ligne Administrateur Points: 24240 Défis: 170 Message

Citer : Posté le 13/12/2023 17:34 | # | Fichier joint


@Zaky202

Here is an add-in that demonstrates both the standard <dirent.h> method and the old BFile method. I tested in on fx-CG 50, on G-III and on an older fx-9860G-like model.

In previous discussions I forgot that gint's opendir() as well as the internal fugue_dir_explore() function use Unix-like normalized paths. So when using opendir() the path for the root should be specified as / instead of \\fls0\, and slash separators are used. gint hides the \\fls0\ nonsense from you.

If you target only the fx-CG and the G-III, then you can use listdir_dirent(), and you should do that (standard methods are better). If you also want to support older black-and-white models, then you have to use listdir_bfile() for now. In the archive the .g3a has been compiled to use the dirent method and the .g1a has been compiled to use the Bfile method.
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 13/12/2023 17:48 | #


Lephenixnoir a écrit :
@Zaky202

Here is an add-in that demonstrates both the standard <dirent.h> method and the old BFile method. I tested in on fx-CG 50, on G-III and on an older fx-9860G-like model.

In previous discussions I forgot that gint's opendir() as well as the internal fugue_dir_explore() function use Unix-like normalized paths. So when using opendir() the path for the root should be specified as / instead of \\fls0\, and slash separators are used. gint hides the \\fls0\ nonsense from you.

If you target only the fx-CG and the G-III, then you can use listdir_dirent(), and you should do that (standard methods are better). If you also want to support older black-and-white models, then you have to use listdir_bfile() for now. In the archive the .g3a has been compiled to use the dirent method and the .g1a has been compiled to use the Bfile method.


Thank You Very Much , its work.
is there any documentation about the other fugue function ?
Lephenixnoir Hors ligne Administrateur Points: 24240 Défis: 170 Message

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


Other Fugue functions? Generally gint functions with fugue in their name are private. If these functions are not documented in one of the headers listed here (which for the filesystem would be either <gint/fs.h> either <gint/bfile.h>) and not part of the standard library then you shouldn't use them. If you need one let me know and I'll do what I can to expose the feature publicly.
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 16/12/2023 19:13 | #


Lephenixnoir a écrit :
Other Fugue functions? Generally gint functions with fugue in their name are private. If these functions are not documented in one of the headers listed here (which for the filesystem would be either <gint/fs.h> either <gint/bfile.h>) and not part of the standard library then you shouldn't use them. If you need one let me know and I'll do what I can to expose the feature publicly.



Sorry bro but there another problem , this function is work but only if there a file in the current path.
for example if :

.  -> dir
.. -> dir
folder -> dir
new - dir

it will pront nothing because there is no files in the current path.

what should i do?


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++) {
        if (strcmp(dp->entries[i]->d_name, ".") == 0 || strcmp(dp->entries[i]->d_name,"..") == 0) continue;
        print_txt(scr, dp->entries[i]->d_name, x_scrl,y_scrl);
    }

    // Close the directory
    fugue_dir_close(dir_data);
}
Lephenixnoir Hors ligne Administrateur Points: 24240 Défis: 170 Message

Citer : Posté le 16/12/2023 20:29 | #


What's the problem? ls prints nothing for empty folders. If you want to print some "folder empty" message just track in you loop whether you reached the print_txt().

Also I don't want to be annoying be fugue_dir_explore is a private gint function, you shouldn't be calling it.
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 16/12/2023 20:47 | #


Lephenixnoir a écrit :
What's the problem? ls prints nothing for empty folders. If you want to print some "folder empty" message just track in you loop whether you reached the print_txt().

Also I don't want to be annoying be fugue_dir_explore is a private gint function, you shouldn't be calling it.


ok what i should do

i mean if there a path for example (/myfolder/)
and inside it there 3 folder , if i use that function i will get nothing
That is, it prints output only if the path contains at least one file (if there are only folders, it will not tell me about them).
Zaky202 Hors ligne Membre Points: 35 Défis: 0 Message

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


Lephenixnoir a écrit :
What's the problem? ls prints nothing for empty folders. If you want to print some "folder empty" message just track in you loop whether you reached the print_txt().

Also I don't want to be annoying be fugue_dir_explore is a private gint function, you shouldn't be calling it.


its work now bro it was a error from me , im sorry.
Thank you for everything you have provided and this great library
i hope u add that private function in the future to the public include , that will be a big help for developers.
Lephenixnoir Hors ligne Administrateur Points: 24240 Défis: 170 Message

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


Alright, if it works then cool.

i hope u add that private function in the future to the public include , that will be a big help for developers.

This function is used for opendir() and readdir(), which are public. opendir() and readdir() work on the same calculators as fugue_dir_explore(), but they are also quasi-standard functions from the C library that work on Windows, Linux etc. These are the ones you should be using as much as possible, and I don't quite understand why you would want to use fugue_dir_explore() in the first place?
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 16/12/2023 22:36 | #


Lephenixnoir a écrit :
Alright, if it works then cool.
This function is used for opendir() and readdir(), which are public. opendir() and readdir() work on the same calculators as fugue_dir_explore(), but they are also quasi-standard functions from the C library that work on Windows, Linux etc. These are the ones you should be using as much as possible, and I don't quite understand why you would want to use fugue_dir_explore() in the first place?


More attractive
I understood from what you said earlier that this function works on more calculators, so I used it
I don't want to touch the code now, it's work

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 33 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