Pathname of a file that is currently loaded


FILEPATH is a variable containing the path of a currently read file.

Possible values: String

The variable FILEPATH represents the pathname of a file. It only has a value while reading a file via read or fread and corresponds to the path specified in read or fread. It can only be accessed from inside the file that is currently read. Using this variable, the read file can access its own pathname and read other files via absolute pathnames, even if it only knows their relative locations with respect to itself.

The value of FILEPATH is a string containing the operating system dependent path to the file that is currently read. The path string terminates with a path separator and, under Windows®, starts with the name of the current volume if this was specified in the read/fread command. Cf. Example 1.


Example 1

Assume that the file C:\TEMP\ contains the following lines of code. It queries its own location via FILEPATH (= C:\TEMP) and reads two files installed relative to the location of via their absolute pathnames C:\TEMP\SubFolder\ and C:\TEMP\SubFolder\, respectively:

print(Unquoted, "FILEPATH" = FILEPATH):

When reading the file, the part C:\TEMP\ of the specified path is accessed by via FILEPATH. It finds the files and if they were installed correctly relative to the path of

read("C:".pathname(Root, "TEMP"), "")

It is good programming style to use platform independent path strings. For this reason, we used the function pathname rather than a mere string concatenation to append appropriate path delimiters.

See Also

MuPAD Functions

Was this topic helpful?