Page 2 of 2

Re: Check if Dir is Subset of a path

Posted: Wed Jul 10, 2013 10:22 am
by eranon
I've tried and it works well on my side (under Windows 7 Pro 64-bit FR edition) using this function (to be sure we talk about the same one) :

Code: Select all

bool IsSubDir(wxString strRefPath, wxString strPathToTest)
{
    wxFileName fn(strPathToTest);
    if (!fn.MakeRelativeTo(strRefPath))
        return false;
    if (fn.GetFullPath().Find("..") == 0)
        return false;
    return true;
}
Here are some test results :
snap_0000194.png
snap_0000194.png (12.88 KiB) Viewed 2331 times

Re: Check if Dir is Subset of a path

Posted: Wed Jul 10, 2013 10:29 am
by evstevemd
eranon wrote:I've tried and it works well on my side (under Windows 7 Pro 64-bit FR edition) using this function (to be sure we talk about the same one) :

Code: Select all

bool IsSubDir(wxString strRefPath, wxString strPathToTest)
{
    wxFileName fn(strPathToTest);
    if (!fn.MakeRelativeTo(strRefPath))
        return false;
    if (fn.GetFullPath().Find("..") == 0)
        return false;
    return true;
}
Here are some test results :
snap_0000194.png
Well I will try it again may be something else was wrong than what I thought.
I use linux, Ubuntu to be specific!

Re: Check if Dir is Subset of a path

Posted: Wed Jul 10, 2013 10:50 am
by eranon
Nothing urgent, but I think it would be nice if you could push the test (maybe related to MakeRelativeTo's underlying code against Linux), evstevemd. On my side, my dev. env. are currently only under Windows and OS X. I'm using Linux too (Ubuntu, Fedora and CentOS), but without any up and running dev environment and wxWidgets right now.

Re: Check if Dir is Subset of a path

Posted: Mon Aug 19, 2013 12:19 pm
by evstevemd
Ah! I found that my code messed up the paths and so the code works fine! :D