NX二次开发-拆分路径为文件夹和文件名
1 void SplitFileName(std::string fullName, std::string &dirName, std::string &fileName)
2 {
3 TrimString(fullName);
4 dirName.clear();
5 fileName.clear();
6
7 if (fullName.empty())
8 return;
9
10 std::size_t pos = fullName.rfind("\");
11 if (pos != std::string::npos)
12 {
13 dirName = fullName.substr(0, pos);
14 fileName = fullName.substr(pos + 1);
15 }
16
17 return;
18 }
1 void TrimString(std::string &str)
2 {
3 string::size_type pos = str.find_last_not_of(' ');
4 if (pos != string::npos)
5 {
6 str.erase(pos + 1);
7 pos = str.find_first_not_of(' ');
8 if (pos != string::npos) str.erase(0, pos);
9 }
10 else
11 {
12 //a blank string
13 str.erase(str.begin(), str.end());
14 }
15 }