13 namespace alps {
namespace fs {
17 typedef std::string::size_type size_type;
19 size_type basedir_len=filename.rfind(
'/');
20 if (basedir_len==string::npos)
26 if (filename.compare(basedir_len, string::npos,
".")==0 ||
27 filename.compare(basedir_len, string::npos,
"..")==0)
30 size_type last_dot_pos=filename.rfind(
'.');
31 if (last_dot_pos==string::npos || last_dot_pos<basedir_len)
34 return filename.substr(last_dot_pos);
40 typedef std::string::size_type size_type;
41 size_type basedir_len=filename.rfind(
'/');
42 if (basedir_len==string::npos)
44 else if (basedir_len==filename.size())
50 if (filename.compare(basedir_len, string::npos,
".")==0 ||
51 filename.compare(basedir_len, string::npos,
"..")==0)
55 if (filename.compare(basedir_len, 3,
"...")==0)
56 return filename.substr(0,basedir_len+2);
59 if (filename.compare(basedir_len, 2,
"..")==0)
60 return filename.substr(0,basedir_len+1);
62 size_type first_dot_pos=filename.find(
'.', basedir_len);
63 return filename.substr(0,first_dot_pos);
69 typedef std::string::size_type size_type;
71 size_type basedir_len=filename.rfind(
'/');
72 if (basedir_len==string::npos)
return filename;
73 if (basedir_len+1==filename.size()) {
74 return basedir_len==0 ?
"/" :
".";
76 return filename.substr(basedir_len+1);
82 typedef std::string::size_type size_type;
84 size_type basedir_len=filename.rfind(
'/');
85 if (basedir_len==string::npos)
return "";
86 if (basedir_len==0 && filename.size()!=1)
return "/";
88 return filename.substr(0,basedir_len);
std::string get_basename(const std::string &path)
Returns the base name of the file (removing leading directories)
std::string remove_extensions(const std::string &filename)
Returns the file name stem with ALL extensions removed.
std::string get_dirname(const std::string &path)
Returns the parent direcory name of the file (removing trailing filename)
std::string get_extension(const std::string &filename)
Returns the file name extension.