bash script to flatten a dir

This commit is contained in:
Lio 2024-01-14 12:27:48 +01:00
parent bc1830a62a
commit 724cf919e4

22
_src/files/flatten.sh Executable file
View file

@ -0,0 +1,22 @@
#!/bin/bash
# Set the source and destination directories
src_dir="./emojis_categorized"
dest_dir="../emojis"
# Navigate to the source directory
cd "$src_dir" || exit
# Find all files in subdirectories and loop through them
find . -type f -not -path '*/\.*' -print0 | while IFS= read -r -d $'\0' file; do
# build the new filename
filename=$(echo "$file" | sed 's/\//+/g' | sed 's/^.+/..\/emojis\//g')
echo "$filename"
echo "$file"
# # Copy the file to the destination directory with the new filename
cp "$file" "$filename"
done
# echo "Flat folder creation complete!"