Check if entry is a folder
Space cpp

Consider the following code:

#SelectExpand
1ALLEGRO_FS_ENTRY* current_directory = al_create_fs_entry(main_folder.c_str() ); 2if (current_directory) 3{ 4 5 if (al_open_directory(current_directory)) 6 { 7 8 ALLEGRO_FS_ENTRY * current_file; 9 while (current_file = al_read_directory(current_directory)) 10 { 11 12 ALLEGRO_PATH * current_path = al_create_path(al_get_fs_entry_name(current_file) ); 13 if (current_path) 14 { 15 16 string file_extension = al_get_path_extension(current_path); 17 18 if (file_extension.empty() ) // folder? 19 folder_list.push_back(al_path_cstr(current_path, ALLEGRO_NATIVE_PATH_SEP) ); 20 21 else if (file_extension == myFileExtension) 22 file_list.push_back(al_path_cstr(current_path, ALLEGRO_NATIVE_PATH_SEP) ); 23 24 25 al_destroy_path(current_path); 26 27 } 28 29 al_destroy_fs_entry(current_file); 30 31 } 32 33 } 34 35 al_destroy_fs_entry(current_directory); 36 37}

If the program happens to find a file without extension it will mistaken it for a folder. How do I make sure if the entry read is actually a folder?

SiegeLord

I believe you do al_get_fs_entry_mode(current_file) & ALLEGRO_FILEMODE_ISDIR.

Space cpp

It worked! Thank you.

Thread #618466. Printed from Allegro.cc