Skip to content

Directory Tools

⬅ Parent


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 - Success
  • 1 - Environment error
  • 2 - 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 exist
  • 1 - Directory is not empty
  • 0 - 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 for mkdir --mode and chmod. 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 - Success
  • 1 - Environment error
  • 2 - 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 for mkdir --mode and chmod. 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 - Success
  • 1 - Environment error
  • 2 - 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. target
  • target - FileDirectory. Required.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - 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. The test argument to test the targeted filePattern. By default uses -d.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - 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 - Success
  • 1 - Environment error
  • 2 - 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 - Success
  • 1 - Environment error
  • 2 - 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 - Success
  • 1 - Environment error
  • 2 - 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 to command.

Return codes

  • 0 - Success
  • 1 - Environment error
  • 2 - Argument error

Requires

pushd popd