[Scilab-users] Fetching the script path

classic Classic list List threaded Threaded
3 messages Options
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Fetching the script path

Hi Scilabers

I have almost always included a neat piece of code in my Scilab scripts, so that I can later dump the plots into e.g.  SVG or PNG files (script path is not write-protected). The code doesn't work anymore:

// Extract the filename and path of this script:
[units,typs,nams]=file(); // nams(1) = script file name incl. path
fpathname=strsplit(nams(1), [filesep()]); // disp(b($-1));
scriptpath = get_absolute_file_path(fpathname($));
chdir(scriptpath);

The above code returns an empty string in scriptpath. I'm using Scilab 6.0.1 (Windows 10) and I wonder what I should do instead?

/Claus


Virus-free. www.avast.com

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Samuel GOUGEON Samuel GOUGEON
Reply | Threaded
Open this post in threaded view
|

Re: Fetching the script path

Le 30/09/2018 à 20:59, Claus Futtrup a écrit :

Hi Scilabers

I have almost always included a neat piece of code in my Scilab scripts, so that I can later dump the plots into e.g.  SVG or PNG files (script path is not write-protected). The code doesn't work anymore:

// Extract the filename and path of this script:
[units,typs,nams]=file(); // nams(1) = script file name incl. path
fpathname=strsplit(nams(1), [filesep()]); // disp(b($-1));
scriptpath = get_absolute_file_path(fpathname($));
chdir(scriptpath);

The above code returns an empty string in scriptpath. I'm using Scilab 6.0.1 (Windows 10) and I wonder what I should do instead?


The following should work.
In Scilab 6, file() additionally lists stderr as unit #0.
Samuel
[units, typs, nams] = file(); 
nams(find(units==0 | units==5 | units==6)) = [];
scriptpath = fileparts(nams($),"path");
chdir(scriptpath);


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Claus Futtrup Claus Futtrup
Reply | Threaded
Open this post in threaded view
|

Re: Fetching the script path

Hi Samuel

Thank you. It works ... (of course :-) ).

Best regards,
Claus

On 30.09.2018 22:03, Samuel Gougeon wrote:
Le 30/09/2018 à 20:59, Claus Futtrup a écrit :

Hi Scilabers

I have almost always included a neat piece of code in my Scilab scripts, so that I can later dump the plots into e.g.  SVG or PNG files (script path is not write-protected). The code doesn't work anymore:

// Extract the filename and path of this script:
[units,typs,nams]=file(); // nams(1) = script file name incl. path
fpathname=strsplit(nams(1), [filesep()]); // disp(b($-1));
scriptpath = get_absolute_file_path(fpathname($));
chdir(scriptpath);

The above code returns an empty string in scriptpath. I'm using Scilab 6.0.1 (Windows 10) and I wonder what I should do instead?


The following should work.
In Scilab 6, file() additionally lists stderr as unit #0.
Samuel
[units, typs, nams] = file(); 
nams(find(units==0 | units==5 | units==6)) = [];
scriptpath = fileparts(nams($),"path");
chdir(scriptpath);



_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users



Virus-free. www.avast.com

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users