From dd5f22ef0a93551ada78ce0983917f0c27197bbe Mon Sep 17 00:00:00 2001 From: hyzboy Date: Wed, 16 Sep 2020 22:02:01 +0800 Subject: [PATCH] add ClipPathname function --- inc/hgl/filesystem/FileSystem.h | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/inc/hgl/filesystem/FileSystem.h b/inc/hgl/filesystem/FileSystem.h index bf1089b..bfd3ad0 100644 --- a/inc/hgl/filesystem/FileSystem.h +++ b/inc/hgl/filesystem/FileSystem.h @@ -138,6 +138,30 @@ namespace hgl fullname.SubString(0,pos+1); } + /** + * 截取一个文件名中的路径名 + * @param filename 文件名 + * @param include_spear_char 是否包含最后的分隔符 + */ + template + inline String ClipPathname(const String &filename,bool include_spear_char=true) + { + if(filename.Length()<=1) + return(String()); + + const T spear_char[] = { '/','\\',':'}; + + const int pos=filename.FindRightChar(spear_char); + + if(pos==-1) + return filename; + else + if(include_spear_char) + return filename.SubString(0,pos); + else + return filename.SubString(0,pos-1); + } + /** * 截取路径最后一个名字 */