Métrologie
Métrologie
MarWin: Did you know... __FILE__
EN

Did you know you can access the name of the current script file?


The line number as well. Let’s say you have a script inside a file called “foo.mpr”:

PROGRAM Foo
BEGIN
                PAUSE ( TEXT = "This is file " + __FILE__ + " and this command is in line " + ITOA(__LINE__))
END

You will get a message like this:


Please note that whereas __FILE__ is a string, __LINE__ is a number. That’s why I used ITOA (read “Integer TO Ascii”) to convert it into a string.

------------------------------------------------------------------------------------------------------------------------------------------------------------

Do you want a challenge?


Write a script that makes a copy of itself. You want to use FOPEN, FGETS and FPRINTF for that.