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.
Citer : Posté le 13/12/2023 12: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)
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.
Citer : Posté le 13/12/2023 13:08 | #
You should probably make a new topic about that
Caltos : G35+EII, G90+E (briquée )
Citer : Posté le 13/12/2023 13:24 | #
You should probably make a new topic about that
Maybe Later
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.
Citer : Posté le 13/12/2023 17:48 | #
@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 ?
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.
Citer : Posté le 16/12/2023 19:13 | #
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);
}
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.
Citer : Posté le 16/12/2023 20:47 | #
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).
Citer : Posté le 16/12/2023 22:26 | #
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.
Citer : Posté le 16/12/2023 22:31 | #
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?
Citer : Posté le 16/12/2023 22:36 | #
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