Page 1 of 2

Scripting: adjust inconsistent path parsing

Posted: 26 Jan 2019 08:08
by bdeshi
Some difference exists in how functions parse paths.

writefile(".\subfolder\data.txt", "content"); // writes to <curpath>\subfolder\data.txt
listfolder(".\subfolder"); // takes <xypath> as base, and lists <xypath>\subfolder.

(I think only goto states this <xypath>-based parsing explicitly.)

But since we can browse to paths with .\ in addressbar, it's only intuitive to expect such relative paths should resolve to <curpath> as base with all functions (except for obvious exceptions, such as load, catalogload, columnlayout, ctbicons, loadlayout, loadsettings, paperfolder, tabset, tagload, toolbar etc which take feature-specific basepaths.)

[ed+] Moreover, most places in the reference say that paths "defaults to the current folder". So it's expected that relative paths will also follow current folder as well.

Or go the other way and make writefile, readfile's parsing of dotted relative paths <xypath>-based as well. :whistle:

Re: Scripting: adjust inconsistent path parsing

Posted: 26 Jan 2019 09:20
by highend

Code: Select all

Or go the other way and make writefile, readfile's parsing of dotted relative paths <xypath>-based as well
If this is done, use <curpath> please...

Re: Scripting: adjust inconsistent path parsing

Posted: 27 Jan 2019 12:13
by admin
1. Yes, SC listfolder had to be fixed. I just did not work as advertised.


2. SC goto is tricky. The behavior of the Address Bar actually depends on this setting (factory default is OFF):
Configuration | General | Controls and More | Miscellaneous | Address Bar relative to application path

Scripts should not depend on this setting, of course.

All in all I tend to change goto to make it work like all (? ... I hope so) other commands: make it relative to <curpath>.
However, this might break old code. So I cannot do that. :|

Re: Scripting: adjust inconsistent path parsing

Posted: 27 Jan 2019 15:45
by bdeshi
ok. listfolder now works okay. I take it other functions will follow suit?
for example: folderreport(,'r', '..\'); // list <xypath>\..\
(I can make a list of commands&functions needing update in a while.)

goto: bummer. burn all old scripts! :pitchfork: :blackstorm:

Also
admin wrote: I just did not work as advertised.
haven't seen any advert, but from what we've seen, you are perfectly fine! :kidding:

Re: Scripting: adjust inconsistent path parsing

Posted: 27 Jan 2019 16:34
by admin
LOL :tup:

Re: Scripting: adjust inconsistent path parsing

Posted: 27 Jan 2019 18:05
by admin
SammaySarkar wrote: 27 Jan 2019 15:45 (I can make a list of commands&functions needing update in a while.)
That would be nice!

I fixed folderreport() in the meantime. Don't see any others... :|

EDIT: ok, I see these: inputfile, inputfolder, resolvepath

Re: Scripting: adjust inconsistent path parsing

Posted: 27 Jan 2019 20:09
by bdeshi
OK, these commands process relative paths as <xypath>-based.

Code: Select all

attrstamp()
copy
copyto      // location <curpath>-based, but source <xypath>-based
moveto      // ^^
backupto    // ^^
pasteto
exists()
filesequal()
flattenfolder()
foldersize()
get()
  * counticons
hash()
hashlist
open
rename
runq    // relative path in directory param is <xypath>-based
runret  // ^^
showhash

broken/incomplete/clarification wanted:

Code: Select all

box        // relative paths not allowed?
highlight  // ^^
html       // ^^
id3tag     // ^^
sync       // ^^
copyas  // are relative paths disallowed in targetpath?
moveas  // ^^
editconf // <xypath>-based. shouldn't it be <xydata>-based like savesettings?
quicksearch() // no relative paths in path param?
run     // relative path in directory param fails in contrast to runq
So far.

Re: Scripting: adjust inconsistent path parsing

Posted: 28 Jan 2019 08:56
by admin
Thanks, that's a long list! But, are you sure that this is not advertised?

Eg for attrstamp the help says:
itemlist: |-separated list of items (full path) to attrstamp;
So you are not supposed to pass a relative path.

Re: Scripting: adjust inconsistent path parsing

Posted: 28 Jan 2019 09:55
by bdeshi
Judge it yourself.
But the fact of the matter is attrstamp() does not fail if given a relative path, so that's already in violation of the docs, so why not go all the way?

Re: Scripting: adjust inconsistent path parsing

Posted: 28 Jan 2019 11:24
by admin
Good point.

Re: Scripting: adjust inconsistent path parsing

Posted: 28 Jan 2019 13:28
by admin
Did them all. Apart from:

Code: Select all

      - exists: needs to react on unaltered inputs to make sense.
      - html(): too ambiguous
      - id3tag: already okay it seems

Re: Scripting: adjust inconsistent path parsing

Posted: 28 Jan 2019 14:26
by bdeshi
wow, great! (I'll add more suggestion here when/if found)

Re: Scripting: adjust inconsistent path parsing

Posted: 29 Jan 2019 10:35
by admin
admin wrote: 28 Jan 2019 13:28 Did them all. Apart from:

Code: Select all

      - exists: needs to react on unaltered inputs to make sense.
Rubbish. SC exists() will be added in the next beta.

Re: Scripting: adjust inconsistent path parsing

Posted: 29 Jan 2019 11:10
by bdeshi
:mrgreen:

Some more notes (sorry if I'm being pedantic or to pressing ):
  • savethumb() does not support relative paths. Plans to support?
  • columnlayout(), loadlayout(), paperfolder() partially accepts relative paths in that they can prepend <xydata>\(columns|layouts|paper), but breaks with .\ and ..\. Do you think these should also correctly support dotted relative paths, being relative to their function-specific base locations?
    so for example, columnlayout("..\..\xydata.bak\columns\defaultcolumns.txt") will work, (load columns from a backup profile directory by pathfinding to parent folders of <xydata>\columns)
  • catalogload also does not support dotted relative paths. This is more confusing because for example, catalogload("..\..\catalog.dat") fails, but the error message has the correct path!

    Code: Select all

    Not Found
    -----------------------------------
    Could not find: 
    
    D:\tools\XYplorer\catalog.dat      (note: this file exists in this exact path.)
    so the error supports relative paths better than the command itself! :ghost:

Re: Scripting: adjust inconsistent path parsing

Posted: 29 Jan 2019 19:13
by admin
SammaySarkar wrote: 29 Jan 2019 11:10 catalogload also does not support dotted relative paths. This is more confusing because for example, catalogload("..\..\catalog.dat") fails, but the error message has the correct path!

Code: Select all

Not Found
-----------------------------------
Could not find: 

D:\tools\XYplorer\catalog.dat      (note: this file exists in this exact path.)
so the error supports relative paths better than the command itself! :ghost:
1) Cannot confirm.

2) The help says: "Can be relative to the application data folder." So I cannot change anything here.