Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Renaming files using Automator and CSV file.

Hi. I am new to programming and trying to work something out that will really help.


I want to rename a folder of files with the numbers from a CSV file column.


For example.


Rename these files with...


column target ID



I've had some luck with automator but can't work out how to name files from the csv.


Any help appreciated


Posted on Mar 30, 2020 4:32 AM

Reply

Similar questions

8 replies

Mar 30, 2020 6:09 AM in response to Tigger42

In order to ensure that the correct rename is applied, two things need to happen.

  1. A two-column CSV with the old filename, new filename
    1. No duplicates in either column
    2. The two-column CSV is read into a list by AppleScript with each list item being these filename pairs
  2. AppleScript will prompt you for a folder containing the old filenames
    1. Finder will generate a list of the filenames in the specified folder
    2. A loop is entered attempting to match the old filename of the CSV list to the current file in the loop
      1. A match causes a rename using the second column of that CSV list
      2. Eventually any old filename that can be matched is renamed (without duplicates)


What I have seen so far is there is no means to ensure a proper old -> new rename mapping.

Mar 30, 2020 4:51 AM in response to Tigger42

Usually, one has a CSV of two columns of unique names, where in each row, the first column is the current filename in the folder, and the second column is the new filename that it is to be renamed too. Otherwise, there is no control over rename mapping.


The data you have shown in the spreadsheet, in any given column, has duplicates.


More information in terms of the first paragraph is needed. Renaming needs a mapping of old to new.

Apr 2, 2020 11:15 AM in response to Tigger42

The reason those image files now have a trailing question mark is that each row of the CSV ended with a carriage-return, line-feed pair (crlf), and though fine for Windows, there should be no carriage return in UNIX line endings here. So, to remove that unwanted ?, you need to run another script in the same directory location as your renamed files.


#!/bin/zsh

# Usage: noq.zsh *.*

for f in "$@"
do
    # trim the ^M (cr) from the file extension
    mv ${f} ${f%?}
done


I called this script noq.zsh, and made it executable in the same folder as the files with the trailing question mark:

chmod +x ./noq.zsh


Then, still in the same directory as the files with the trailing question mark:

./noq.zsh *.*


and the files will be fixed.

Renaming files using Automator and CSV file.

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.