Created
April 11, 2020 10:28
-
-
Save charlieegan3/f8e7d83603d37f3ce68c1dad1a1b3733 to your computer and use it in GitHub Desktop.
safe_flatten
This file contains hidden or 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 | |
# run safe_flatten for each in folder | |
set -eo pipefail | |
root_dir=$1 | |
if [ -z "$root_dir" ] | |
then | |
echo missing root dir | |
exit | |
fi | |
find "$root_dir" -mindepth 1 -maxdepth 1 -type d | while read dir; do | |
echo $dir | |
./safe_flatten.sh $dir | |
done |
This file contains hidden or 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 | |
# move all files in folder to the top level, | |
# rename as sum of file contents to handle duplicates, | |
# remove all empty folders | |
set -eo pipefail | |
root_dir=$1 | |
if [ -z "$root_dir" ] | |
then | |
echo missing root dir | |
exit | |
fi | |
echo dir: $root_dir | |
find $root_dir -type f | while read file; do | |
new_file_name=$(md5sum "$file" | awk '{print $1}') | |
filename=$(basename -- "$file") | |
extension="${filename##*.}" | |
mv "$file" "$root_dir/$new_file_name.$extension" | |
done | |
find $root_dir -type d -empty -delete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment