Getting a directory name from a filename
Using Boost.Filesystem: boost::filesystem::path p(“C:\\folder\\foo.txt”); boost::filesystem::path dir = p.parent_path();
Using Boost.Filesystem: boost::filesystem::path p(“C:\\folder\\foo.txt”); boost::filesystem::path dir = p.parent_path();
dir=/home/smith/Desktop/Test parentdir=”$(dirname “$dir”)” Works if there is a trailing slash, too.
os.path.dirname(os.path.abspath(__file__)) is indeed the best you’re going to get. It’s unusual to be executing a script with exec/execfile; normally you should be using the module infrastructure to load scripts. If you must use these methods, I suggest setting __file__ in the globals you pass to the script so it can read that filename. There’s no … Read more