Help language development. Donate to The Perl Foundation
path-utils - low-level path introspection utility functions
use path-utils; # export all subs use path-utils <path-exists>; # only export sub path-exists say path-exists($filename); 0 or 1
path-utils provides a number of low-level path introspection utility functions for those cases where you're interested in performance, rather than functionality.
All subroutines take a (native) string as the only argument.
Note that these functions only return native int
and native num
values, which can be used in conditions without any problems, just don't expect them to be upgraded to Bool
values.
Also note that all functions (except path-exists
) expect the path to exist. An exception will be thrown if the path does not exist. The reason for this is that in situations where you are already sure a path exists, there is no point checking for its existence again if you e.g. would like to know its size.
use path-utils <path-exists>; # only export sub path-exists
By default all utility functions are exported. But you can limit this to the functions you actually need by specifying the names in the use
statement.
To prevent name collisions and/or import any subroutine with a more memorable name, one can use the "original-name:known-as" syntax. A semi-colon in a specified string indicates the name by which the subroutine is known in this distribution, followed by the name with which it will be known in the lexical context in which the use
command is executed.
use path-utils <path-exists:alive>; # export "path-exists" as "alive" say alive "/etc/passwd"; # 1 if on Unixy, 0 on Windows
In alphabetical order:
Returns number of seconds since epoch as a num
when path was last accessed.
Returns the number of filesystem blocks allocated for this path.
Returns the preferred I/O size in bytes for interacting wuth the path.
Returns number of seconds since epoch as a num
when path was created.
Returns the device number of the filesystem on which the path resides.
Returns 1 if paths exists, 0 if not.
Returns the size of the path in bytes.
Returns the numeric group id of the path.
Returns the number of hard links to the path.
The path has the SETGID bit set in its attributes.
Returns the inode of the path.
Returns 1 if path is a device, 0 if not.
Returns 1 if path is a directory, 0 if not.
Returns 1 if the path has a filesize of 0.
Returns a non-zero integer value if path is executable by the current user.
Returns 1 if path appears to be the top directory in a GitHub repository (as recognized by having a .github
directory in it).
Returns 1 if path appears to be the top directory in a Git repository (as recognized by having a <.git> directory in it).
Returns a non-zero integer value if path is executable by members of the group of the path.
Returns a non-zero integer value if path is readable by members of the group of the path.
Returns a non-zero integer value if path is writable by members of the group of the path.
Returns a non-zero integer value if path is owned by the current user.
Returns a non-zero integer value if path is owned by the group of the current user.
Returns a non-zero integer value if path is executable by the owner of the path.
Returns a non-zero integer value if path is readable by the owner of the path.
Returns a non-zero integer value if path is writable by the owner of the path.
Returns a non-zero integer value if path is readable by the current user.
Returns 1 if path is a regular file, 0 if not.
The path has the STICKY bit set in its attributes.
Returns 1 if path is a symbolic link, 0 if not.
Returns 1 if path is looks like it containes text, 0 if not.
Returns a non-zero integer value if path is executable by anybody.
Returns a non-zero integer value if path is readable by anybody.
Returns a non-zero integer value if path is writable by any body.
Returns a non-zero integer value if path is writable by the current user.
Returns number of seconds since epoch as a num
when the meta information of the path was last modified.
Returns the numeric unix-style mode.
Returns number of seconds since epoch as a num
when path was last modified.
Returns the numeric user id of the path.
Elizabeth Mattijsen [email protected]
Source can be located at: https://github.com/lizmat/path-utils . Comments and Pull Requests are welcome.
If you like this module, or what I’m doing more generally, committing to a small sponsorship would mean a great deal to me!
Copyright 2022 Elizabeth Mattijsen
This library is free software; you can redistribute it and/or modify it under the Artistic License 2.0.