2.2 KiB
FS (filesystem) module
This module provides functions to inspect the file system. It is available starting with version 0.53.0.
File lookup rules
Non-absolute paths are looked up relative to the directory where the
current meson.build
file is.
If specified, ~
is expanded to the user home directory.
exists
Takes a single string argument and returns true if an entity with that name exists on the file system. This can be a file, directory or a special entry such as a device node.
is_dir
Takes a single string argument and returns true if a directory with that name exists on the file system. This method follows symbolic links.
is_file
Takes a single string argument and returns true if an file with that name exists on the file system. This method follows symbolic links.
is_symlink
Takes a single string argument and returns true if the path pointed to by the string is a symbolic link.
File Parameters
hash
The fs.hash(filename)
method computes the requested hash sum of a file.
The available hash methods include: md5, sha1, sha224, sha256, sha384, sha512.
samefile
The fs.samefile(filename1, filename2)
method allows determining if two filenames refer to the same file.
Perhaps a meson.build file in one place refer to a symlink and in another place a
relative path and/or absolute path. The samefile
method allows determining if these
are the same file.
Examples:
x = 'foo.txt'
y = 'sub/../foo.txt'
z = 'bar.txt' # a symlink pointing to foo.txt
fs.samefile(x, y) # true
fs.samefile(x, z) # true
Filename modification
with_suffix
The with_suffix
method is a string manipulation convenient for filename modifications.
It allows changing the filename suffix like:
swap suffix
original = '/opt/foo.ini'
new = fs.with_suffix('.txt') # /opt/foo.txt
add suffix
original = '/opt/foo'
new = fs.with_suffix('.txt') # /opt/foo.txt
compound suffix swap
original = '/opt/foo.dll.a'
new = fs.with_suffix('.so') # /opt/foo.dll.so
delete suffix
original = '/opt/foo.dll.a'
new = fs.with_suffix('') # /opt/foo.dll
The files need not actually exist yet for this method, as it's just string manipulation.