getpathcomponent($path, "base") wrong when folder has dot
-
- Posts: 1416
- Joined: 04 Nov 2008 05:35
- Location: Hanoi, Vietnam
getpathcomponent($path, "base") wrong when folder has dot
with a folder with dot in folder name such as C:\first.second
getpathcomponent($path, "base")
would return "first" instead of "first.second"
getpathcomponent($path, "base")
would return "first" instead of "first.second"
I'm a casual coder using AHK language. All of my xys scripts:
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
http://www.xyplorer.com/xyfc/viewtopic. ... 243#p82488
Re: getpathcomponent($path, "base") wrong when folder has do
Per the help file, "base" is base "filename" without extension and doesn't apply to folders. Something like this... 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.
Code: Select all
::text getpathcomponent("G:\House\Damas.cus\Home_inspection.pdf", "base");
Windows 11, 22H2 Build 22621.1555 at 100% 2560x1440
Re: getpathcomponent($path, "base") wrong when folder has do
gpc() ( ) 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:I only wish the sc would consider strings ending in either slash as folder.
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");
Icon Names | Onyx | Undocumented Commands | xypcre
[ this user is asleep ]
[ this user is asleep ]
-
- Site Admin
- Posts: 60357
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: getpathcomponent($path, "base") wrong when folder has do
I don't find these so odd. To me the results are expected.SammaySarkar wrote:gpc() ( ) 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:I only wish the sc would consider strings ending in either slash as folder.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");
FAQ | XY News RSS | XY Twitter
Re: getpathcomponent($path, "base") wrong when folder has do
In general it would be nice if getpathcomponent could check if an item is a folder and return the correct elements
One of my scripts helped you out? Please donate via Paypal
-
- Site Admin
- Posts: 60357
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: getpathcomponent($path, "base") wrong when folder has do
What are the correct elements in the above examples? Apart from Base everything is correct now IMO.
FAQ | XY News RSS | XY Twitter
Re: getpathcomponent($path, "base") wrong when folder has do
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
One of my scripts helped you out? Please donate via Paypal
-
- Site Admin
- Posts: 60357
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: getpathcomponent($path, "base") wrong when folder has do
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.
FAQ | XY News RSS | XY Twitter
Re: getpathcomponent($path, "base") wrong when folder has do
But this is not what you expect when you use gpc() on a folder with dots in it...
One of my scripts helped you out? Please donate via Paypal
-
- Site Admin
- Posts: 60357
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: getpathcomponent($path, "base") wrong when folder has do
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
text getpathcomponent("R:\abc.def\ghi.jkl", "base"); //ghi
text getpathcomponent("R:\abc.def\ghi.jkl\", "base"); //ghi.jkl = NEW BEHAVIOR
FAQ | XY News RSS | XY Twitter
Re: getpathcomponent($path, "base") wrong when folder has do
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:
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
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.
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.
One of my scripts helped you out? Please donate via Paypal
-
- Site Admin
- Posts: 60357
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: getpathcomponent($path, "base") wrong when folder has do
Yes, a flag would be an option. Maybe later.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
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:".
Probably my intention had been to do it just for "drive", but buggily I implemented it for all modes.
FAQ | XY News RSS | XY Twitter
Re: getpathcomponent($path, "base") wrong when folder has do
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
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
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
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
-
- Site Admin
- Posts: 60357
- Joined: 22 May 2004 16:48
- Location: Win8.1 @100%, Win10 @100%
- Contact:
Re: getpathcomponent($path, "base") wrong when folder has do
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.
FAQ | XY News RSS | XY Twitter