Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/bash
- shopt -s nocaseglob nocasematch
- cd "$(dirname "$0")"/"$(echo override | tr '[:upper:]' '[:lower:]')"
- readonly VERSION=1.2 SUPPORTED_FILE_TYPES=(tga tpc)
- echo "Version ${VERSION}\n\nPlease be sure this file is located in the game's root folder (where the game's .exe is located) and not in the Override folder.\n\nThis script deletes duplicate TGA or TPC files in the Override folder.\n"
- confirm_delete() {
- read -p "Delete $1? [y/n]: " input_del
- case "${input_del,,}" in [y]*) rm "$1"; echo "Deleted $1";; esac
- }
- delete_duplicates() {
- local files=($(find . -iname "*.$1" -print0 | xargs -0))
- if (( ${#files[@]} )); then
- for file in "${files[@]}"; do
- local companion_file_path="${file%.*}.tpc"
- [[ "$1" == "tpc" ]] && companion_file_path="${file%.*}.tga"
- if [[ -e "$companion_file_path" ]]; then
- if (( dry_run )); then
- echo "Would delete $file (duplicate found: $companion_file_path)"
- else
- echo "Deleting $file (duplicate found: $companion_file_path)"
- confirm_delete "$file"
- (( deleted_files++ ))
- fi
- fi
- done
- (( deleted_files )) || echo "No duplicates found for ${1^^} files."
- else
- echo "No ${1^^} files found."
- fi
- }
- dry_run=0
- while getopts "n" opt; do [[ $opt == n ]] && dry_run=1; done
- for type in "${SUPPORTED_FILE_TYPES[@]}"; do
- read -p "Do you want to delete duplicate ${type^^} files? [y/n]: " input_del
- echo ""
- [[ "$input_del" =~ [yY](es)? ]] && delete_duplicates "$type" "$dry_run"
- done
- echo -e "\nFinished"
Add Comment
Please, Sign In to add comment