Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » Check if entry is a folder

Credits go to SiegeLord for helping out!
This thread is locked; no one can reply to it. rss feed Print
Check if entry is a folder
Space cpp
Member #16,322
May 2016

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?

----------
My games

SiegeLord
Member #7,827
October 2006
avatar

I believe you do al_get_fs_entry_mode(current_file) & ALLEGRO_FILEMODE_ISDIR.

"For in much wisdom is much grief: and he that increases knowledge increases sorrow."-Ecclesiastes 1:18
[SiegeLord's Abode][Codes]:[DAllegro5]:[RustAllegro]

Space cpp
Member #16,322
May 2016

It worked! Thank you.

----------
My games

Go to: