Page 1 of 1

getpathcomponent($path, "base") wrong when folder has dot

Posted: 11 Oct 2014 05:06
by binocular222
with a folder with dot in folder name such as C:\first.second
getpathcomponent($path, "base")
would return "first" instead of "first.second"

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 11 Oct 2014 14:32
by klownboy
Per the help file, "base" is base "filename" without extension and doesn't apply to folders. Something like this...

Code: Select all

::text getpathcomponent("G:\House\Damas.cus\Home_inspection.pdf", "base");
does properly return Home_inspection. So since it's suppose to apply to the file, XY is probably treating your folder like a file and splitting it at the extension.

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 11 Oct 2014 15:27
by bdeshi
gpc() ( :whistle: ) doesn't check if given string is a folder etc, so it can be said to be working as intended with b222's string.
But gpc() by default processes everything as filepaths, simply stripping trailing/extra /:\ and tokenizing the string. Some odd results:

Code: Select all

::text getpathcomponent("D:\", "file");
::text getpathcomponent("D:\Docs.Proj\", "file");
::text getpathcomponent("G:\", "base");
::text getpathcomponent("G:\", "file");
::text getpathcomponent("Impossible^&?*:!],=..\file.txt", "parent"); 
I only wish the sc would consider strings ending in either slash as folder.

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 14:40
by admin
SammaySarkar wrote:gpc() ( :whistle: ) doesn't check if given string is a folder etc, so it can be said to be working as intended with b222's string.
But gpc() by default processes everything as filepaths, simply stripping trailing/extra /:\ and tokenizing the string. Some odd results:

Code: Select all

::text getpathcomponent("D:\", "file");
::text getpathcomponent("D:\Docs.Proj\", "file");
::text getpathcomponent("G:\", "base");
::text getpathcomponent("G:\", "file");
::text getpathcomponent("Impossible^&?*:!],=..\file.txt", "parent"); 
I only wish the sc would consider strings ending in either slash as folder.
I don't find these so odd. To me the results are expected.

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 15:09
by highend
In general it would be nice if getpathcomponent could check if an item is a folder and return the correct elements :)

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 16:09
by admin
What are the correct elements in the above examples? Apart from Base everything is correct now IMO.

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 16:48
by highend
Imho:
text getpathcomponent("R:\abc.def\ghi.jkl", "path");
Current : R:\abc.def
Expected: R:\abc.def\ghi.jkl
Comment : Help file states: path: [default] The path without any file.
There is no file at all so returning "R:\abc.def"
is actually not the (full path), but the path of the parent folder

text getpathcomponent("R:\abc.def\ghi.jkl", "parent");
OK

text getpathcomponent("R:\abc.def\ghi.jkl", "file");
Current : ghi.jkl
Expected: <empty>
Comment : There isn't any file!

text getpathcomponent("R:\abc.def\ghi.jkl", "base");
Current : ghi
Expected: ghi.jkl
Comment: Folders don't have any extensions at all, so the base is the folder name without path

text getpathcomponent("R:\abc.def\ghi.jkl", "ext");
Current : jkl
Expected: <empty>
Comment : Folders don't have any extensions at all...

text getpathcomponent("R:\abc.def\ghi.jkl", "count");
OK

text getpathcomponent("R:\abc.def\ghi.jkl", "component", -x);
OK

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 17:02
by admin
OK, I have a different understanding of "file" and "path" in this context. To me "file" is the last component, and path is all other components.

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 17:16
by highend
But this is not what you expect when you use gpc() on a folder with dots in it...

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 17:19
by admin
Yes, the "base" case could be improved. At least when the path ends with a slash (I don't want to test for folder vs file because this takes time and can be troublesome in case of network paths). So I suggest this change:

text getpathcomponent("R:\abc.def\ghi.jkl", "base"); //ghi
text getpathcomponent("R:\abc.def\ghi.jkl\", "base"); //ghi.jkl = NEW BEHAVIOR

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 17:24
by TheQwerty
I have mixed feelings about this...

For GPC to determine that 'R:\abc.def\ghi.jkl' is a folder and not a file it has to check if it exists.
That has the potential to make it slower, but that also means working with paths you know don't exist could become more difficult.

Perhaps this should be under a flag parameter?
flag
0 = Default (as it is now)
1 = Check if path is a folder or file first.


Frankly I'm more agitated by the treatment of drive letters & servers because it can become difficult to determine if you got back a drive letter or folder name:

Code: Select all

echo GetPathComponent('C:\abc', 'path'); // 'C' - expected 'C:'
echo GetPathComponent('\\server', 'path'); // '\' - expected '\\server
echo GetPathComponent('C:\abc', 'parent'); // 'C' - would prefer 'C:'
echo GetPathComponent('C:\C\abc', 'parent'); // 'C' - okay

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 06 Nov 2014 17:27
by highend
The last time I used gpc to create a script and relied on the result it failed (http://www.xyplorer.com/xyfc/viewtopic.php?f=3&t=12733).

Maybe make it optional if we want it to check for files / folders and take the risk that it slows down (but delivers correct results) like TheQwerty suggests.

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 07 Nov 2014 08:56
by admin
TheQwerty wrote:I have mixed feelings about this...

For GPC to determine that 'R:\abc.def\ghi.jkl' is a folder and not a file it has to check if it exists.
That has the potential to make it slower, but that also means working with paths you know don't exist could become more difficult.

Perhaps this should be under a flag parameter?
flag
0 = Default (as it is now)
1 = Check if path is a folder or file first.


Frankly I'm more agitated by the treatment of drive letters & servers because it can become difficult to determine if you got back a drive letter or folder name:

Code: Select all

echo GetPathComponent('C:\abc', 'path'); // 'C' - expected 'C:'
echo GetPathComponent('\\server', 'path'); // '\' - expected '\\server
echo GetPathComponent('C:\abc', 'parent'); // 'C' - would prefer 'C:'
echo GetPathComponent('C:\C\abc', 'parent'); // 'C' - okay
Yes, a flag would be an option. Maybe later.

I admit I agree with your expectations listed above. The current behavior looks buggy to me, so I think it's okay to change it (which may break some scripts...).


BTW, although I document everything I currently cannot find the reason why I decided to remove the colon after the drive letter. :?

Code: Select all

v11.40.0205 - 2012-08-19 12:52
    * SC getPathComponent: Now any trailing colon (:) is removed from the
      returns, so "drive" will now return the drive letter alone: "E" 
      instead of "E:".
The resulting issue had been discussed already before: http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=12219
Probably my intention had been to do it just for "drive", but buggily I implemented it for all modes.

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 09 Nov 2014 20:26
by neil9090
Just wondering if the logic should be to add an additional component fullpath, change behaviour of path just to return the path without server/drive would break many existing scripts so maybe pathonly component?
component
pathonly = folderpath
fullpath = C:\folderpath
path = folderpath

Code: Select all

echo GetPathComponent('C:\abc', 'path'); // 'C' - expected '' (nothing) <<change in behaviour>>
echo GetPathComponent('\\server', 'path'); // '\' - expected '\\server

<<new option fullpath>>
echo GetPathComponent('C:\abc\abc', 'fullpath'); // 'C:\abc\abc' (if a directory) else C:\abc
echo GetPathComponent('C:\abc', 'fullpath'); // 'C:\abc' (if a directory) else C:\
echo GetPathComponent('C:\file.txt', 'fullpath'); // 'C:\'  

echo GetPathComponent('C:\abc', 'parent'); // 'C' - would prefer 'C:'
echo GetPathComponent('C:\C\abc', 'parent'); // 'C' - okay
I have just discovered this issue when using "C:\dir\file.txt" the gpc path resolved to "C:\dir" but when a call to gpc is done in the root it resolved to be "C" not "C:\"
thus read this item and the other item http://www.xyplorer.com/xyfc/viewtopic.php?f=5&t=12219
e.g. C:\file.txt returns C not C: but in a subdirectory C:\dir\file.txt return C:\dir

Re: getpathcomponent($path, "base") wrong when folder has do

Posted: 10 Nov 2014 09:46
by admin
As I said I think the previous behavior was buggy and never intended like this by me. It was a mistake that I have corrected now.