From c2c907b2bf14c6fdd8379c6b47e88a779eab3838 Mon Sep 17 00:00:00 2001 From: kichik Date: Fri, 26 Nov 2004 15:26:49 +0000 Subject: [PATCH] added get_file_name which extracts the file name from a path git-svn-id: https://svn.code.sf.net/p/nsis/code/NSIS/trunk@3780 212acab6-be3b-0410-9dea-997c60f758d6 --- Source/util.cpp | 6 ++++++ Source/util.h | 1 + 2 files changed, 7 insertions(+) diff --git a/Source/util.cpp b/Source/util.cpp index f7a934d5..e912a85a 100644 --- a/Source/util.cpp +++ b/Source/util.cpp @@ -530,3 +530,9 @@ string get_dir_name(const string& path) { return path.substr(0, last_separator_pos); } +string get_file_name(const string& path) { + string::size_type last_separator_pos = path.rfind(PLATFORM_PATH_SEPARATOR_C); + if (last_separator_pos == string::npos) + return path; + return path.substr(last_separator_pos + 1, string::npos); +} diff --git a/Source/util.h b/Source/util.h index a5eb382f..0fe8464b 100644 --- a/Source/util.h +++ b/Source/util.h @@ -48,6 +48,7 @@ size_t my_strftime(char *s, size_t max, const char *fmt, const struct tm *tm); std::string get_full_path(const std::string &path); std::string get_dir_name(const std::string& path); +std::string get_file_name(const std::string& path); #ifndef _WIN32 char *CharPrev(const char *s, const char *p);