Forum Navigation
Treate Posix style FilePath on Windows
Moderators:
kris
Posted: 10/18/07 03:52:24Some time, we recive file path from Posix server, or send file path to Posix file path. but seems no way to treate Posix style file path on Windows :
auto s = FilePath(r"/a/b/c.txt"); Cout(s.parent).newline; //print nothingmy solution is:
//from dwin.io.FilePath char[] parent(char[] fullname) out (result) { assert(result.length <= fullname.length); } body { uint i; for (i = fullname.length; i > 0; i--) { version(Win32) { if (fullname[i - 1] == ':') break; if (fullname[i - 1] == '\\') { i--; break; } if (fullname[i - 1] == '/')//to support server path, by yidabu.com 20070718 { i--; break; } } version(linux) { if (fullname[i - 1] == '/') { i--; break; } } } return fullname[0 .. i]; } //parent debug(UnitTest) unittest { char[] p = "/a/b/c.txt"; p = parent(p); assert(p == "/a/b"); }