file to quickly bulk rename filenames and escape/ replace sequences
This commit is contained in:
parent
bf419bfd98
commit
b5f66ebcb8
28
scripts/escapeFilenames.sh
Executable file
28
scripts/escapeFilenames.sh
Executable file
@ -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
|
Loading…
Reference in New Issue
Block a user