Files - nsrosenqvist/quickscript GitHub Wiki
file_extension()
A simple way to retrieve the file extension from a file name
Parameter | Explanation |
---|---|
$1 (string) | The file to extract the extension from |
return (string) - Returns the file extension
author: Niklas Rosenqvist
file_name()
A simple way to retrieve the file name without the extension from a file name
Parameter | Explanation |
---|---|
$1 (string) | The file to extract the name from |
return (string) - Returns the file name without the extension
author: Niklas Rosenqvist
strip_multi_slash()
Delete all multiple occurrences of forward slashes to get a clean path
Parameter | Explanation |
---|---|
$1 (string) | The path to strip forward slashes from |
return (string) - Returns the string without multiple slashes
author: Niklas Rosenqvist
is_mountpoint()
Check if a path is a mountpoint
It uses the program mountpoint to see if anything is mounted at the path specified. Even though it's mounted the path might be inaccessible (filesystem errors) so the second parameter gives the option to verify that a file you specify can be found within the filesystem. For example if you know you have a file called ".mounted" in the root of the filesystem.
Parameter | Explanation |
---|---|
$1 (string) | Optional file to check for |
return (int) - Returns 0 if it's a mountpoint and non-zero if it's not a mountpoint
author: Niklas Rosenqvist
tempdir()
Get the name of a temporary directory, specific to this script instance
It's supposed to be used together with make_tempdir but is required to retrieve the tempdir's name
Parameter | Explanation |
---|---|
$1 (string) | The file to extract the name from |
return (string) - Returns the name of the temporary directory
author: Niklas Rosenqvist
make_tempdir()
Creates this script instance's temporary directory
This function creates the temporary directory which's name is retrieved by running "tempdir". It also traps the end of the script so that it automatically gets deleted upon exit.
return (int) - 0 or non-zero depending upon success
author: Niklas Rosenqvist
remove_tempdir()
Manually deletes the temporary directory
If you for some reason would like to delete the temporary directory for this script instance then you can use this function. Otherwise it will get deleted anyway when the script exits.
return (int) - 0 or non-zero depending upon success
author: Niklas Rosenqvist
compare_versions()
A function that compares to strings with traditional version formatting
It's pretty flexible and can handle many different kinds of version string. It can compare 0.1.002.0.0 to 0.1.2 and many similar cases. The comparators That are suported are =, !=, >= >, <= and <.
Parameter | Explanation |
---|---|
$1 (string) | Second version string |
$2 (string) | Comparator |
return (int) - 0 if the statement was true and 1 if not.
author: Niklas Rosenqvist