perlperl
asked on
boost library to normalize the path
Is there any boost library that will normalize the unix file path.
For example)
1) input ////root///dir1///////dir2 /dir3 should be normalized to
/root/dir1/dir2/dir3
2) input root///////dir4 should be normalized to
root/dir4
I was just wondering if there is boost library then i don't want to write my own
For example)
1) input ////root///dir1///////dir2
/root/dir1/dir2/dir3
2) input root///////dir4 should be normalized to
root/dir4
I was just wondering if there is boost library then i don't want to write my own
Oops- forgot to link the docs: http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/path.htm
ASKER
Sure I will try and see.
Its not errornous, one can do ls on such a path on unix and it does work.
so i need to handle such case in my code
Its not errornous, one can do ls on such a path on unix and it does work.
so i need to handle such case in my code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Great!! This works like a charm.
Do I have use try catch?
Do I have use try catch?
ASKER
i know some boost need to catch as it can throw exception
I could not see that anything there would cause an exception (except a completely buggy path, but just in case:
See http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/exception.htm
filesystem::path pathName( “////root///dir1///////dir2/dir3” );
try {
pathName.normalize();
} catch(filesystem::filesystem_exception& e) {
// handle here
}
cout << pathName.string() << endl();
See http://www.boost.org/doc/libs/1_31_0/libs/filesystem/doc/exception.htm
ASKER
I think so its
filesystem_error and not exception
catch(boost::filesystem::f ilesystem_ error& e
filesystem_error and not exception
catch(boost::filesystem::f
Yes, sorry - typo :-/
I even linked the correct page and spelled it wrong *grr*
I even linked the correct page and spelled it wrong *grr*
Open in new window