Directory Tools
Usage
directoryRelativePath [ directory ]
Given a path to a file, compute the path back up to the top in reverse (../..)
If path is blank, outputs ..
Essentially converts the slash / to a .., so convert your source appropriately.
directoryRelativePath "/" -> ".."
directoryRelativePath "/a/b/c" -> ../../..
Writes to standard output
Relative paths, one per line
Arguments
directory- String. A path to convert.
Return codes
0- Success1- Environment error2- Argument error
Usage
pathIsAbsolute [ path ]
Is a path an absolute path?
Arguments
path- String. Optional. Path to check.
Return codes
0- if all paths passed in are absolute paths (begin with/).1- one ore more paths are not absolute paths
Usage
directoryIsEmpty [ directory ]
Does a directory exist and is it empty?
Arguments
directory- Directory. Optional. Directory to check if empty.
Return codes
2- Directory does not exist1- Directory is not empty0- Directory is empty
Usage
fileDirectoryRequire [ --help ] [ --mode fileMode ] [ --owner ownerName ] fileDirectory ...
Given a list of files, ensure their parent directories exist Creates the directories for all files passed in.
Arguments
--help- Flag. Optional. Display this help.--mode fileMode- String. Optional. Enforce the directory mode formkdir --modeandchmod. Affects directories after it in the command line; supply multiple modes and order your directories if needed. Set to-to reset to no value.--owner ownerName- String. Optional. Enforce the directory owner the directory. Affects all directories supplied AFTER it on the command line. Set to-to reset to no value.fileDirectory ...- FileDirectory. Required. Test if file directory exists (file does not have to exist)
Examples
logFile=./.build/$me.log
fileDirectoryRequire "$logFile"
Return codes
0- Success1- Environment error2- Argument error
Requires
chmod throwArgument usageArgumentString decorate catchEnvironment dirname
Usage
directoryRequire [ directoryPath ... ] [ --help ] [ --mode fileMode ] [ --owner ownerName ]
Given a list of directories, ensure they exist and create them if they do not.
Arguments
directoryPath ...- One or more directories to create--help- Flag. Optional. Display this help.--mode fileMode- String. Optional. Enforce the directory mode formkdir --modeandchmod. Affects directories after it in the command line; supply multiple modes and order your directories if needed. Set to-to reset to no value.--owner ownerName- String. Optional. Enforce the directory owner the directory. Affects all directories supplied AFTER it on the command line. Set to-to reset to no value.
Examples
directoryRequire "$cachePath"
Return codes
0- Success1- Environment error2- Argument error
Requires
throwArgument usageArgumentFunction usageArgumentString decorate catchEnvironment dirname chmod chown
Usage
directoryClobber source target
Copy directory over another sort-of-atomically
Arguments
source- Directory. Required. targettarget- FileDirectory. Required.
Return codes
0- Success1- Environment error2- Argument error
Usage
directoryParent startingDirectory --pattern filePattern [ --test testExpression ]
Finds a file above startingDirectory, uses testExpression to test (defaults to -d)
Arguments
startingDirectory- Required. EmptyString|RealDirectory. Uses the current directory if blank.--pattern filePattern- RelativePath. Required. The file or directory to find the home for.--test testExpression- String. Optional. Zero or more. Thetestargument to test the targetedfilePattern. By default uses-d.
Return codes
0- Success1- Environment error2- Argument error
directoryPathSimplify
Normalizes segments of
/./and/../in a path without
Usage
directoryPathSimplify path ...
Normalizes segments of /./ and /../ in a path without using realPath
Removes dot and dot-dot paths from a path correctly
Arguments
path ...- File. Required. One or more paths to simplify
Return codes
0- Success1- Environment error2- Argument error
directoryNewestFile
Find the newest modified file in a directory
Usage
directoryNewestFile directory [ --find findArgs ... -- ]
Find the newest modified file in a directory
Arguments
directory- Directory. Required. Directory to search for the newest file.--find findArgs ... --- Arguments. Optional. Arguments delimited by a double-dash (or end of argument list)
Return codes
0- Success1- Environment error2- Argument error
directoryOldestFile
Find the oldest modified file in a directory
Usage
directoryOldestFile directory [ --find findArgs ... -- ]
Find the oldest modified file in a directory
Arguments
directory- Directory. Required. Directory to search for the oldest file.--find findArgs ... --- Arguments. Optional. Arguments delimited by a double-dash (or end of argument list)
Return codes
0- Success1- Environment error2- Argument error
Usage
directoryChange directory command [ ... ]
Run a command after changing directory to it and then returning to the previous directory afterwards.
Arguments
directory- Directory. Required. Directory to change to prior to running command.command- Callable. Required. Thing to do in this directory....- Arguments. Optional. Arguments tocommand.
Return codes
0- Success1- Environment error2- Argument error
Requires
pushd popd