Example 1: Extracting the parts of a file name
This program uses the file functions to extract the directory name,
the base name, the root name, and the file extension:
IMPORT os
MAIN
DISPLAY "Dir name = ", os.Path.dirName(arg_val(1))
DISPLAY "Base name = ", os.Path.baseName(arg_val(1))
DISPLAY "Root name = ", os.Path.rootName(arg_val(1))
DISPLAY "Extension = ", os.Path.extension(arg_val(1))
END MAIN
Example results:
Path | os.Path.dirname | os.Path.basename | os.Path.rootname | os.Path.extension |
---|---|---|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
These examples use UNIX™ file names. On Windows® the result would be different, as the file name separator is a
backslash (\
).