diff --git a/sortbooks.sh b/sortbooks.sh index 7749003..4722a2b 100755 --- a/sortbooks.sh +++ b/sortbooks.sh @@ -34,6 +34,10 @@ find_or_create_directory_for_target() { # Function to move files based on source keywords move_files() { + # Delete duplicate files using fdupes + echo "Removing duplicate files in $WATCHED_DIR..." + fdupes -r -N --delete "$WATCHED_DIR" + for FILE in "$WATCHED_DIR"/*.{epub,pdf,mobi,txt}; do if [[ -f "$FILE" ]]; then FILENAME=$(basename "$FILE") @@ -54,9 +58,9 @@ move_files() { move_files # Monitor for new or modified files and then sort them -while inotifywait -e create -e moved_to -e modify "$WATCHED_DIR"; do +while inotifywait -r -e create -e moved_to -e modify "$WATCHED_DIR"; do move_files - fdupes -r -N --delete . done +shopt -u nocasematch