Created
January 31, 2017 21:51
-
-
Save aidanhmiles/8781928519f3c03b8222d689799f1756 to your computer and use it in GitHub Desktop.
Copy files from A to B, preserving directory hierarchy from wherever the script is executed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
main() { | |
local files=() | |
# Method 1 | |
# while read -r fname; do | |
# derp+=("$fname") | |
# done < <(ag -g html base/) | |
# Method 2 | |
mapfile -t files < <( ag -g html . ) | |
for item in "${files[@]}" | |
do | |
local target_dir="../templates/$(dirname $item)/" | |
if [[ -d "$target_dir" ]]; then | |
echo "dir $target_dir does exist"; | |
else | |
echo "dir $target_dir no exist" | |
echo "creating it" | |
mkdir -p $target_dir | |
fi | |
echo "copying $item to $target_dir" | |
cp "$item" "$target_dir" | |
echo | |
echo | |
done | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment