copy folder structure only

This commit is contained in:
Q
2019-12-07 08:38:11 +02:00
parent e81fb4714f
commit f21cbfd5fb
2 changed files with 41 additions and 0 deletions

40
files/cp-dir-struct Executable file
View File

@@ -0,0 +1,40 @@
#!/bin/bash
set -e
function helpexit() {
echo Usage: $( basename "$0" ) -v source[/] target
echo Copy directory structure to a folder.
echo 'This command always recurses to subdirectories!'
echo '-v verbose'
exit
}
VERBOSE=""
for ((i=1; i<=${#@}; i++)) {
[[ "${!i}" = "-h" ]] && helpexit
[[ "${!i}" = "--help" ]] && helpexit
[[ "${!i}" = "-v" ]] && { VERBOSE="-v"; continue; }
[[ -z "$SRC" ]] && { SRC="${!i}"; continue; }
[[ -z "$TGT" ]] && { TGT="${!i}"; continue; }
echo Too many arguments
exit 1
}
is_subfolder=1
if [[ "${SRC: -1}" = "/" ]]; then
is_subfolder=0
fi
src_abs=$( realpath "$SRC" )
tgt_abs=$( realpath "$TGT" )
src_base=$( basename "$src_abs" )
if [[ $is_subfolder -eq 1 ]]; then
tgt_abs+="/$src_base"
fi
find "$SRC" -mindepth 1 -type d -printf "$tgt_abs/%P\0" | while read -d $'\0' file; do
mkdir -p $VERBOSE "$file"
done