Bonjour tout le monde,
Je suis en train d'explorer la bibliothèque boost, et notamment tout ce qui concerne la partie "filesystem". Je me demandais si il y avait un moyen simple d'obtenir le chemin relatif d'un élément (fichier ou dossier) à partir d'un chemin donné.
Par exemple, en reprenant les exemples fournis, voici un ls récursif :
Code :
- bool ls_rec( const fs::path &dir_path ) {
- if ( !fs::exists( dir_path ) ) return false;
-
- fs::directory_iterator end_itr;
-
- for ( fs::directory_iterator itr( dir_path ); itr != end_itr; ++itr ) {
- if ( fs::is_directory( *itr ) ) {
- std::cout << "Repertoire " << itr->relative_path().string() << std::endl ;
- ls_rec( *itr ) ;
- }
- else {
- std::cout << "Fichier : " << itr->relative_path().string() << std::endl ;
- }
- }
-
- return true ;
- }
- int main( int argc, char* argv[] )
- {
- fs::path full_path( fs::initial_path() ) ;
- if ( argc > 1 )
- full_path = fs::system_complete( fs::path( argv[1], fs::native ) );
-
- ls_rec(full_path) ;
- }
|
Cela m'affiche à chaque fois le chemin complet pour chaque fichier/dossier. J'aimerais pouvoir afficher le chemin relatif au chemin initial, par exemple.
Est-ce possible "directement" avec les fonctionnalitées offertes par boost::filesystem ? J'ai parcouru la doc, mais j'ai peut-être mal interprété quelque chose.
Merci à tous, @+
Message édité par Evadream -jbd- le 29-02-2004 à 15:33:13