From b5f66ebcb800115bc9c8c25b6cec52ca8ca2e15c Mon Sep 17 00:00:00 2001 From: fabian Date: Fri, 28 Apr 2023 21:32:21 +0200 Subject: [PATCH] file to quickly bulk rename filenames and escape/ replace sequences --- scripts/escapeFilenames.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100755 scripts/escapeFilenames.sh diff --git a/scripts/escapeFilenames.sh b/scripts/escapeFilenames.sh new file mode 100755 index 0000000..ee17aaa --- /dev/null +++ b/scripts/escapeFilenames.sh @@ -0,0 +1,28 @@ +#!/usr/bin/env bash +set -euo pipefail + +# for i in *placehoder*; do mv "$i" "${i//placeholder/replacement}" done + +replacements= +declare -A replacements +unset replacements[0] +replacements[' ']='_'; +replacements[':']='_'; +while [[ $# > 0 ]]; do + replacements["$1"]="$2"; + shift 2; +done + +for toReplace in "${!replacements[@]}"; do + echo "$toReplace" + replacement=${replacements[$toReplace]} + echo "$replacement" + for i in *; do + echo "$i" + if [[ ! -e "$i" || "$i" == "${i//$toReplace/$replacement}" ]]; then + continue; # weird behaviour with single space makes this necessary + fi + echo "mv $i -> ${i//$toReplace/$replacement}"; + mv "$i" "${i//$toReplace/$replacement}"; + done +done