MCPcopy Create free account
hub / github.com/clechasseur/pathcopycopy / ExtractFolderFromPath

Method ExtractFolderFromPath

PathCopyCopy/src/PluginUtils.cpp:95–111  ·  view source on GitHub ↗

Given a path to a file or folder, will return the path to its parent folder. Ex: C:\Foo\Bar.txt => C:\Foo @param p_rPath Complete path on input, parent's path on output. @return true if we did find a parent path and returned it.

Source from the content-addressed store, hash-verified

93 // @return true if we did find a parent path and returned it.
94 //
95 bool PluginUtils::ExtractFolderFromPath(std::wstring& p_rPath)
96 {
97 // Find the last delimiter in the path and truncate path
98 // as appropriate to return only the parent's path.
99 std::wstring::size_type lastDelimPos = p_rPath.find_last_of(L"/\\");
100 const bool found = (lastDelimPos != std::wstring::npos);
101 if (found) {
102 // We found a delimiter, clear everything after that
103 // (and the delimiter as well). Exception: if we're left
104 // with only a drive letter, keep the delimiter.
105 if (lastDelimPos <= 2) {
106 ++lastDelimPos;
107 }
108 p_rPath.erase(lastDelimPos);
109 }
110 return found;
111 }
112
113 //
114 // Returns a list of a path's parents, in reverse order.

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected