GNOME Bugzilla – Bug 336531
Glib should have a function that changes a relative path to an absolute one.
Last modified: 2006-03-29 19:34:15 UTC
It would be nice if Glib had a funtion that changed a relative path to an absolute one (to go along with all of the other nice path functions that it has.) An implementation of this funtion using glibmm follows: Glib::ustring path_to_abs_path(Glib::ustring path) { unsigned parents = 0; Glib::ustring cwd = Glib::get_current_dir(); Glib::ustring::size_type pos; // find out how far up we have to go. while( (pos = path.find("../", 0)) !=Glib::ustring::npos ) { path.erase(0, 3); parents++; } // now erase that many directories from the path to the current // directory. while( parents ) { if ( (pos = cwd.rfind ('/')) != Glib::ustring::npos) { // remove this directory from the path cwd.erase (pos); } parents--; } return cwd + '/' + path; }
This would be part of a general path handling api. *** This bug has been marked as a duplicate of 8616 ***