FILEPATH

Pathname of a file that is currently loaded

Description

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.

Examples

Example 1

Assume that the file C:\TEMP\file.mu 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 file.mu via their absolute pathnames C:\TEMP\SubFolder\file1.mu and C:\TEMP\SubFolder\file2.mu, respectively:

print(Unquoted, "FILEPATH" = FILEPATH):
read(FILEPATH.pathname("SubFolder")."file1.mu"):
read(FILEPATH.pathname("SubFolder")."file2.mu"):

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

read("C:".pathname(Root, "TEMP"), "file.mu")
 FILEPATH = C:\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?