Bulk renaming portion of files using automator workflow and csv file
Hey Guys,
I have been trying to use Automator to rename portions of 300 files names. I can use the find and replace on finder but I will have to do it for 200 files. I copied this code from https://discussions.apple.com/thread/251756941. However, I do not know how to adapt the code to find and replace the portions. So I want to replace only sections of the filename. Assistance will be appreciated?
Test csv data:
The file names below:
Automator workflow:
The code that needs updating:
DIR="$1"
shift
CSV="$1"
# unnecessary, but if the CSV file doesn't exist, exit
# [[ -s "$CSV" ]] || exit 1
cd "${DIR}"
# works with comma delimited CSV
while IFS=',' read oldfile newfile
do
# do not process headings
[[ ! "${oldfile}" =~ \.(jpg|jpeg|png)$ ]] && continue
# Skip entry if old filename in CSV doesn't exist in current folder
[[ -e "${oldfile}" ]] || continue
# strip any trailing empty comma delimiters from end of newfile
newfilex="${newfile//,/}"
# replace any detected illegal forward slash with an underscore
newfilex="${newfilex//\//_}"
# rename files
/bin/mv "${oldfile}" "${newfilex}"
# remove any double-quoted items and if from Windows, trim the CR from the line
done < <(sed -e 's/"//g;' "${CSV}" | tr -d '\r')
# done < "${CSV}"
sleep 1
/usr/bin/osascript -e 'display dialog "Processing complete."' &> /dev/null
exit 0
MacBook Pro 15″, macOS 11.0