nixos-config/components/media/sanitize_folder.sh
2024-06-07 22:56:52 +02:00

19 lines
373 B
Bash

#!/bin/bash
# todo : add a dry-run
sanitize() {
shopt -s extglob
filename=$(basename "$1")
directory=$(dirname "$1")
filename_clean="${filename//+([^[:alnum:]_-\\.])/_}"
if [[ $filename != "$filename_clean" ]]; then
mv -v --backup=numbered "$1" "$directory/$filename_clean"
fi
}
export -f sanitize
find "$1" -depth -exec bash -c 'sanitize "$0"' {} \;