Dirstruct

This module allows you to extract or create a directory structure. It can be used to extract the structure of a given directory whose contents are too large to copy, or to re-create a directory structure for testing purposes.

Usage

There are two main commands in this module:

  • biomate dirstruct extract: Extracts the directory structure of a given directory.
  • biomate dirstruct create: Creates a directory structure based on a given template.

Extracting Directory Structure

The command biomate dirstruct extract allows you to extract the directory structure of a specified directory. This is useful, in combination with the create command, to recreate the structure without copying the contents.

To run the extraction, the command is biomate dirstruct extract --source-path <SOURCE_PATH> --output-file <OUTPUT_FILE>, where <SOURCE_PATH> is the path to the directory you want to extract, and <OUTPUT_FILE> is the path to the output file where the directory structure will be saved. If the output file is not specified, the structure will be printed to the standard output.

Output File Format

The output file contains a list of relative paths to directories and files, in top-down hierarchical order, with each line representing either a directory or a file. By default, a tab character is used to separate the path component from a tag indicating whether the path is a directory ('dir') or a file ('file'). For example:

path/to/directory/    dir
path/to/directory/file.txt    file
path/to/another/directory/    dir
path/to/another/directory/file2.txt    file

The tab-separated tags are optional and can be omitted by using the --no-tags option. In this case, the output will simply be a list of relative paths without any additional information. However, the tags can be useful when regenerating the directory structure to distinguish between directories and files (see below).

Creating Directory Structure

The command biomate dirstruct create allows you to create a directory structure based on a given file, usually generated by the extract command. However, the input file can also be manually created or modified to suit your needs.

To create a directory structure, the command is biomate dirstruct create --input-file <INPUT_FILE> --output-path <OUTPUT_PATH>, where <INPUT_FILE> is the path to the file containing the information on the directory structure, and <OUTPUT_PATH> is the path where it will be created. If the output path is not specified, the structure will be created in the current working directory.

Note: The create command will not delete any additional files or directories already present in the output path. It will only create the directories and files specified in the input file. If a file already exists at a specified path, it will be overwritten without warning.

The create command will only touch the generated files, meaning it will create empty files with the specified names. If you want to populate the files with content, you will need to do that separately after the structure has been created.

Input File Format

The input file should contain a list of relative paths to directories and files, similar to the output format of the extract command. Each line should represent either a directory or a file, with an optional tab character separating the path from a tag indicating whether it is a directory ('dir') or a file ('file'). As an example, please refer to the output file format described above.

If the tags are present, the create command will use them to determine whether to create a directory or a file at each path. If the tags are omitted, the command will assume that all paths without an extension are directories and all paths with an extension are files. In this case, if a file cannot be create, for whatever reason, the module will attempt to create the parent directories first, and then create the file.