Directory Tools
directoryRelativePath
Given a path to a file, compute the path back
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
pathIsAbsolute
Is a path an absolute path?
Usage
pathIsAbsolute path ...
Is a path an absolute path?
Return Code: 0 - if all paths passed in are absolute paths (begin with /).
Return Code: 1 - one ore more paths are not absolute paths
Arguments
- none
Return codes
0- Success1- Environment error2- Argument error
directoryIsEmpty
Does a directory exist and is it empty?
Usage
directoryIsEmpty [ directory ]
Does a directory exist and is it empty? Return Code: 2 - Directory does not exist Return Code: 1 - Directory is not empty Return Code: 0 - Directory is empty
Arguments
directory- Directory. Optional. Directory to check if empty.
Return codes
0- Success1- Environment error2- Argument error
fileDirectoryRequire
Given a list of files, ensure their parent directories exist
Usage
fileDirectoryRequire file1 file2 ...
Given a list of files, ensure their parent directories exist
Creates the directories for all files passed in.
Arguments
--help- Optional. Flag. 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
directoryRequire
Given a list of directories, ensure they exist and create
Usage
directoryRequire dir1 [ dir2 ... ]
Given a list of directories, ensure they exist and create them if they do not.
Arguments
dir1- One or more directories to create--help- Optional. Flag. 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
directoryClobber
Copy directory over another sort-of-atomically
Usage
directoryClobber source target
Copy directory over another sort-of-atomically
Arguments
- none
Return codes
0- Success1- Environment error2- Argument error
directoryParent
Finds a file above
startingDirectory, usestestExpressionto test (defaults
Usage
directoryParent startingDirectory filePattern [ 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- Required. RelativePath. 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 ...- Required. File. 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 ... --- Optional. Arguments. 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 ... --- Optional. Arguments. Arguments delimited by a double-dash (or end of argument list)
Return codes
0- Success1- Environment error2- Argument error
directoryChange
Run a command after changing directory to it and then
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