Want to highlight a helpful answer? Upvote!

Did someone help you, or did an answer or User Tip resolve your issue? Upvote by selecting the upvote arrow. Your feedback helps others! Learn more about when to upvote >

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

Rearrange order of Finder file names

I have many (400 +) files that I wish to sort then save in different formats.

Present format:


123 Fred and Dick see Charlie.mp4

124 Charlie and Fred see Dick.mp4

etc.


I wish to batch change the files to:


Fred and Dick see Charlie 123.mp4

Charlie and Fred see Dick 124.mp4

etc.


'Name Mangler' can only delete or add characters.

'A Better Finder Rename' does the same.


Any suggestions of how to do this simply would be appreciated.



Thank you,


David

iMac (27-inch Mid 2011), OS X Mavericks (10.9)

Posted on Jan 26, 2014 4:36 PM

Reply
3 replies

Jan 26, 2014 6:21 PM in response to David Morton5

This is actually reasonable easy to do via AppleScript, as long as there is a clear pattern to follow.


For example, do all the file names follow the same pattern? Is it always a 3 digit number? or does the number of digits vary?

Are all the filenames using spaces (i.e. is it sufficient to move the first n characters up to the space to the end of the file name?)


If you can clarify that, it should be pretty easy to throw something together.

Jan 26, 2014 7:56 PM in response to David Morton5

Try this bash script.

This example works on files in the folder: Untitled Folder on the Desktop:

Test on a sample of your files


#!/bin/bash


for f in ~/Desktop/Untitled\ Folder/*

do

path=${f%/*}

fileExt=${f##*.}

prefix=$( echo "${f##*/}" | egrep -o "^[0-9]*" )

name=$( echo "${f##*/}" | egrep -o "[^0-9 ].*$" )

newname="${name%.*} $prefix.$fileExt"

mv "$f" "${f%/*}/$newname"

done

Jan 27, 2014 8:55 AM in response to Tony T1

Tony T!:

You are an officer and a gentleman!


Worked like a charm....Thank you.

David



Camelot:


Thanks for your input.

All file names are as listed.

Yes always 3 digits.

Yes space always after 3 digit number.


What my examples tried to show was:


Cut first 3 numbers plus space.

Discard space.

Add space to end of existing file name (before .mp4)

Paste 3 numbers, after space.


Thank you,

David

Rearrange order of Finder file names

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