Added list directory structure script.
This commit is contained in:
47
list_directory_structure.sh
Executable file
47
list_directory_structure.sh
Executable file
@@ -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 <snapshot-id>"
|
||||
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"
|
||||
Reference in New Issue
Block a user