I am experiencing a bug in my GUI Tollkit when trying to list files and folders in a given folder.
My code is the following :
- Code: Tout sélectionner
int FileDialogBoxWidget::listdir(const char *path)
{
char name[255];
struct dirent *ent;
DIR *dir = opendir(path);
while((ent = readdir(dir)))
{
strcpy(name, path);
strcat(name,"/");
strcat(name, ent->d_name);
DIR *test = opendir( name );
if(test)
{
closedir(test);
folderlist->additem( (char *) ent->d_name );
}
else
{
filelist->additem( (char *) ent->d_name );
}
}
closedir(dir);
return 0;
}
It loops the correct number of times but ent->d_name always return the name of the first item (in my case the name of the first folder) in the considered folder to scrutinize.
I made the same routine on my linux distribution and it works perfectly well. The code is as follows :
- Code: Tout sélectionner
int listdir(const char *path)
{
char name[255];
struct dirent *ent;
DIR *dir = opendir(path);
while((ent = readdir(dir)))
{
//Test whether it's a directory
strcpy(name, path);
strcat(name,"/");
strcat(name, ent->d_name);
DIR *test = opendir( name );
if(test) // This is a directory and we add to the folder list widget
{
closedir(test);
printf( "[ %s ] \n", ent->d_name );
}
else // this is a file and we add to the folder list widget
{
printf( " %s \n", ent->d_name );
}
}
closedir(dir);
return 0;
}
No need to say that I checked many thing to try to identify if the folderlist and filelist works fine, and they do.
I do not understand what's happening, does anyone also met that bug/issue ?
The bug is in the following file : https://github.com/SlyVTT/Widget-for-TI-NSpire/blob/main/Toolkit/FileDialogBoxWidget.cpp
Ciao
Sly