c++ - Boost directory iterator "no such file or directory" -
i using boost::filesystem::directory_iterator iterate on contents of folder(non-recursively) , count how many elements in folder. able iterate on entire folder, when boost::filesystem::directory_iterator advances end iterator error thrown:
libc++abi.dylib: terminating uncaught exception of type boost::filesystem::filesystem_error: boost::filesystem::directory_iterator::construct: no such file or directory
i not see how using directory iterator incorrectly in code, code throws error:
boost::filesystem::path pcdfiledir(getpcdfilepath().string().substr(0, getpcdfilepath().string().find_last_of(boost::filesystem::path::preferred_separator))); std::cout << "pcdfiledirectory: " << pcdfiledir.string() << std::endl; size_t file_count = 0; for(boost::filesystem::directory_iterator itr(pcdfiledir); itr != boost::filesystem::directory_iterator(); ++itr){ std::cout << itr->path() << std::endl; file_count++; } return file_count; }
pcddir has value ../out/autzen. in ../out/autzen 54 folders containing pcd files following patter autzen_1, autzen_2, etc, , autzen.pcd. output of print statement in loop this:
"../out/autzen/autzen.pcd" "../out/autzen/autzen_1" "../out/autzen/autzen_10" "../out/autzen/autzen_11" "../out/autzen/autzen_12" "../out/autzen/autzen_13" "../out/autzen/autzen_14" "../out/autzen/autzen_15" "../out/autzen/autzen_16" "../out/autzen/autzen_17" "../out/autzen/autzen_18" "../out/autzen/autzen_19" "../out/autzen/autzen_2" "../out/autzen/autzen_20" "../out/autzen/autzen_21" "../out/autzen/autzen_22" "../out/autzen/autzen_23" "../out/autzen/autzen_24" "../out/autzen/autzen_25" "../out/autzen/autzen_26" "../out/autzen/autzen_27" "../out/autzen/autzen_28" "../out/autzen/autzen_29" "../out/autzen/autzen_3" "../out/autzen/autzen_30" "../out/autzen/autzen_31" "../out/autzen/autzen_32" "../out/autzen/autzen_33" "../out/autzen/autzen_34" "../out/autzen/autzen_35" "../out/autzen/autzen_36" "../out/autzen/autzen_37" "../out/autzen/autzen_38" "../out/autzen/autzen_39" "../out/autzen/autzen_4" "../out/autzen/autzen_40" "../out/autzen/autzen_41" "../out/autzen/autzen_42" "../out/autzen/autzen_43" "../out/autzen/autzen_44" "../out/autzen/autzen_45" "../out/autzen/autzen_46" "../out/autzen/autzen_47" "../out/autzen/autzen_48" "../out/autzen/autzen_49" "../out/autzen/autzen_5" "../out/autzen/autzen_50" "../out/autzen/autzen_51" "../out/autzen/autzen_52" "../out/autzen/autzen_53" "../out/autzen/autzen_54" "../out/autzen/autzen_6" "../out/autzen/autzen_7" "../out/autzen/autzen_8" "../out/autzen/autzen_9"
as can see, covers every element in folder correctly.
edit: using range-based loop suggested @chris_stathis exact syntax:
for(auto &file : boost::filesystem::directory_iterator(pcdfiledir)){ std::cout << file.path() << std::endl; file_count++; }
does not resolve error.
i had same problem, @ first boost threw same error yours started throw std::bad_alloc. resolved in 2 steps.
- i built boost libraries same version of gcc used compile project. since have different versions of gcc on target machine (4.4.7 , 6.3.0), guess there may issues caused this.
- i removed cmake temporary folders , files , rebuilt project scratch. try if use cmake. don't forget "make clean".
i suspect key solve problem step 2.
Comments
Post a Comment