2

So I teach a class and a few of my students have Macs. Literally the only thing I have encountered is this .bat issue.

We use Excel to start with a list of filenames in one column, and a list of new filenames in the other column, and then create a bat file. The new names are not intuitive and they do not follow a pattern, so typical logic can't handle this; we must rely on the list.

Do Macs have something that can work? I would love to provide a solution.

This is what it looks like in windows (this assumes all files are in the same folder, and the bat file runs from the root; it is just as possible to use fullpaths)

rename accounting2016.xls ID0001.xls
rename vacationphoto01.jpg ID0042.jpg
rename BuildingPlans.docx ID0189.docx

2 Answers 2

3

If I read the question correctly, you are generating the batch file from some sort of exporting process from the Excel columns containing the command and two file names?

In such a case you can just change the rename command to "Mac equivalent" mv. The file now contains

mv accounting2016.xls ID0001.xls
mv vacationphoto01.jpg ID0042.jpg
mv BuildingPlans.docx ID0189.docx

Then you can run the commands listed in the file with e.g. Bash:

bash renames.txt

Note, that if the file names contain whitespace or other special characters you should surround them with quotes, but I think that is the case also in Windows.

2
  • I suppose asking how I run the commands in bash is a different question. Is that straightforward? Is bash native to Mac or is there an install?
    – jqning
    Commented Oct 6, 2016 at 2:52
  • 1
    Bash comes pre-installed on Macs. You can run the commands listed in a file (e.g. renames.txt) by opening a Terminal window and issuing a command bash renames.txt in the directory where the file is located - just like in Windows. Bash then reads the individual commands from the file, line by line, executing them one after another.
    – Jawa
    Commented Oct 6, 2016 at 7:56
1

Unix command line tools are what you want and you or the Mac users in your group should undertake some basic tutorials on this. It is often called shell programming.

The command you want here is mv (short for move) The shell script you would generate (equivalent to the batch file) would include

mv accounting2016.xls ID0001.xls
mv vacationphoto01.jpg ID0042.jpg
mv BuildingPlans.docx ID0189.docx

Note that this is an exact match as long as you don't use wild cards. Wildcards are treated differently in Windows command files and Unix shells there are a few things you can do with the former only. This is because the wild card expansion is done by the rename command in Windows and by the shell in Unix

2
  • Using mv instead of rename is straightforward, thanks for that. How do I run the shell script?
    – jqning
    Commented Oct 6, 2016 at 2:48
  • You should read a shell tutorial - as if you are asking that question there are other shell things you need to know. But in effect run the command as sh filename
    – mmmmmm
    Commented Oct 6, 2016 at 12:12

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .