[scilab-Users] Scilab equivalent of mfilename?

Iai Masafumi ax iai at axelspace.com
Tue Nov 15 06:33:18 CET 2011


I am wanting something like __FILE__ macro of C language. It should be 
useful in debugging and in managing a lot of data files and figures 
generated by different scripts.

The code you provided did not work as I wanted when multiple script 
files are nested. To solve this, slight modification is made:

[u,t,n]=file();
i = grep(n',"/(?:.*\.sci|.*\.sce)$/","r");
p = n(i(length(i)));   // <--- modified.

Still, this method does not give me the file name of *.sci itself. 
Suppose you have two files, fileA.sci and fileB.sce. A function is 
defined in fileA.sci and is called from fileB.sce. If you put the above 
code in fileA.sci and execute the script, fileB.sce, then you get 
"fileB.sce" in the varialbe, p.

Is there any way to get the file name of sci file as well?


Iai


(2011/11/15 11:23), Samuel Gougeon wrote:
> Le 15/11/2011 01:21, Iai Masafumi ax a écrit :
>> Hi
>>
>> Does Scilab have a command like mfilename in Matlab? I want to get the
>> name of a currently running script file.
>>
> If you really don't know the name of the current script, you may use the
> following:
>
> [u,t,n]=file();
> i = grep(n',"/(?:.*\.sci|.*\.sce)$/","r");
> p = n(i(1))
> // and if you need only the script name without its path nor the file
> extension:
> basename(p)
>
> Samuel
>



More information about the users mailing list