From f6b542dabf0249e1316344a265ea76962896005f Mon Sep 17 00:00:00 2001 From: Leonard Excoffier <48970393+excoffierleonard@users.noreply.github.com> Date: Fri, 9 Aug 2024 19:39:22 -0400 Subject: [PATCH] Added list directory structure script. --- list_directory_structure.sh | 47 +++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100755 list_directory_structure.sh diff --git a/list_directory_structure.sh b/list_directory_structure.sh new file mode 100755 index 0000000..545366f --- /dev/null +++ b/list_directory_structure.sh @@ -0,0 +1,47 @@ +#!/bin/bash + +# This script generates a directory structure that mirrors the file tree of a Duplicacy snapshot. +# Duplicacy gives a command to list the files in a snapshot, but it doesn't provide a way to visualize the directory structure. + +# Check if a snapshot ID is provided as an argument. +if [ $# -ne 1 ]; then + echo "Usage: $0 " + exit 1 +fi + +# Define the snapshot ID from the argument. +SNAPSHOT_ID="$1" + +# Define a temporary working directory. +WORKING_DIR="./duplicacy_snapshot_tree" + +# Create the working directory. +mkdir -p "$WORKING_DIR" + +# Change to the working directory. +cd "$WORKING_DIR" || exit + +# Generate the list of files in the snapshot and process them. +duplicacy list -r "$SNAPSHOT_ID" -files | awk 'NR > 4 {lines[NR] = substr($0, index($0, $5))} END {for (i = 5; i < NR; i++) print lines[i]}' | while IFS= read -r file_path; do + # Trim trailing whitespace that might have been added + file_path=$(echo "$file_path" | sed 's/[[:space:]]*$//') + + # Check if file_path is non-empty. + if [[ -n "$file_path" ]]; then + if [[ "$file_path" == */* ]]; then + # Create the directory structure for each file path. + mkdir -p "$(dirname "$file_path")" + fi + # Create empty files to simulate the snapshot's file tree. + touch "$file_path" + fi +done + +# Use the `tree` command to display the directory structure, including hidden files. +tree -a + +# Change back to the original directory. +cd .. + +# Clean up the generated directory structure. +rm -rf "$WORKING_DIR"