Home » Extra libraries, Code snippets, applications etc. » U++ users applications in progress and useful code snippets, including reference examples! » DirectoryUp doesn't seem to work.
Re: DirectoryUp doesn't seem to work. [message #18571 is a reply to message #18568] |
Thu, 09 October 2008 14:07   |
mrjt
Messages: 705 Registered: March 2007 Location: London
|
Contributor |
|
|
The function actually seems to work quite well once you understand what the goal is:
1- Ignore non-valid paths
2- Enforce POSIX minimum path of '/'
2- On Win32 jump from 'C:\' & '\\Server' style paths straight to '' path
Without these conditions the function would be:
name = GetFileTitle(dir);
dir = GetFileFolder(dir);
The only change I would make would be to remove trailing DIR_SEPs, but you can always add something like this:
if (dir.GetLength() > 1) {
const char *eos = dir.End()-1;
int cnt = 0;
while (*eos == DIR_SEP && eos > dir.Begin()) {
eos--;
cnt++;
}
if (cnt) {
#ifdef PLATFORM_WIN32
if (*eos != ':')
#endif
{
dir.Remove(dir.GetLength()-cnt, cnt);
}
}
}
[Updated on: Thu, 09 October 2008 14:10] Report message to a moderator
|
|
|
Goto Forum:
Current Time: Sun Jun 08 07:49:35 CEST 2025
Total time taken to generate the page: 0.04388 seconds
|