PDA

View Full Version : Batch renaming file extensions (Mac)


SpringHeeledJack
24th Jun 2013, 21:38
My good self, master of all things IT, have managed to change 4860 jpg files into Unix Executable Files in the process of renaming them. I obviously didn't pay enough attention to the boxes needing checking :hmm: :O The solution is to rename the file extension, and it works. However to do this 4859 more times would take a week. Any suggestions how to do this easily and effortlessly ? The renaming program I use doesn't seem to have a reverse/reverting action and the developers haven't answered my pleas for help as of yet (5days). Heeeelp!



SHJ

mixture
24th Jun 2013, 22:14
My good self, master of all things IT

Well dear master, not wishing to teach granny how to suck eggs, I shall merely prompt your memory to remember the fact that OS X is a BSD based platform (put simply .... similar in concept to Linux).

Under Application->Utilities, you will find one of my favourite tools .... Terminal.

A bit of command line wizardry that I'm sure you, dear master, already know, and you should have the solution to the problem put before you.

In the future, bear in mind that a lot can be achieved through the magic terminal without having to resort to third party utility apps. But with power comes the need to make sure you use it carefully (and always make backups !).

Should you require further detail, I can provide further hints in the right direction. :cool:

SpringHeeledJack
25th Jun 2013, 07:40
Mr Mixture, one was being ironic in a self-depreciating way :) and automator and terminal are beyond one's capabilities. I had seen something on a developer's forum whereby altering a string of code would do the trick, but at this point I don't feel inclined to take the chance and possibly corrupt said files with my messing about.


SHJ

jimtherev
25th Jun 2013, 08:34
...but at this point I don't feel inclined to take the chance and possibly corrupt said files with my messing about.

SHJ
How wise! However, I humbly suggest a cunning plan I've used in the past: copy a hunk of the files onto a temp folder and experiment with the copies. If that works, then it should with the rest?

mixture
25th Jun 2013, 08:40
SHJ,

There is no such thing as a unix executable file as such, so I'm guessing you meant the windows ".exe" ?

Disclaimer : Although I've put an anti-fat-finger step in the below, I would still encourage you to use your preferred backup routine before proceeding !

(1) Identify the absolute location of the files

• Right click on file & select "Get Info" (or just highlight file and hit "cmd-I")
•*Make a note of the value given to you in the "Where" field

(2) Fire up Terminal

• Applications -> Utilities -> Terminal
• Change directory to the directory above the one given in the where field.
e.g. for /Users/mixture/Desktop/random you would enter
cd /Users/mixture/Desktop
•For your own sanity, create a compressed archive of the folder you're about to tamper with (the below is based on the directory name above, change to suit your own):
tar cvf random_25June013.tar random/
gzip -9 random_25June013.tar
You should see your filenames streaming by on the screen. Second line is not strictly necessary, it doesn't have much effect on image files anyway, but you might as well compress them as much as possible.
•Enter the dragons lair …
cd random
•enter the following……
for i in *exe; do j=`echo $i | sed 's/exe$/jpg/g'`;mv "$i" "$j";done

Important note re: the above, note the difference between backticks and single quote !

Keef
25th Jun 2013, 11:31
Complicated in Mac, it seems!

In Windows, it's one line in the command screen -

rename *.wrongname *.rightname

I would certainly copy the files into another directory and do the business on that. If it works, move the files or rename the "new" directory.

mixture
25th Jun 2013, 12:02
Complicated in Mac, it seems!

Erm, no... :=

You can skip half my steps. As I said, half of them are only there for fat-finger protection purposes... you could just do

cd /Users/mixture/Desktop/folder
(which you would have to do on windows anyway)

then...

for i in *exe; do j=`echo $i | sed 's/exe$/jpg/g'`;mv "$i" "$j";done

There are 101 other ways to do that line. Some shorter, some longer.... I just picked that one.

Sure there's no "rename" command, but yah boo sucks.... what it does mean is you've got more powerful options available to you .... e.g. you can do file renames via the find command ....which means you can do fancy tricks with the atime/mtime and other flags.... in Windows you would probably have to resort to multiple lines of PowerShell scripting, whilst on Mac it can be done in a short one-liner.

There's also nothing stopping you writing a script called "rename" on a Mac and using that with appropriate input arguments. :p

mixture
25th Jun 2013, 12:59
Actually... following keef's moaning.....


zsh
autoload -U zmv
cd /Users/mixture/Desktop/folder
noglob zmv -W *.exe *.jpg


or in a couple of lines.....


cd /Users/mixture/Desktop/folder
zsh -c "autoload zmv; noglob zmv -W *.exe *.jpg"


Would probably be the visually cleanest way to do it on a mac (omitting the fat-finger protection).

For keef's benefit, you could probably even go one step further.....


zsh
autoload -U zmv
alias rename='noglob zmv -W'


then you just go....

cd /Users/mixture/Desktop/folder
rename *.exe *.jpg

Keef
25th Jun 2013, 15:03
No, not moaning, just remarking on how much more complicated Mac stuff is.
It confirms that I was right not to go further down that path. I'm not clever enough.

Milo Minderbinder
25th Jun 2013, 15:20
3 Easy Ways to Batch Rename Files on the Mac | Mactuts+ (http://mac.tutsplus.com/tutorials/os-x/3-easy-ways-to-batch-rename-files-on-the-mac/)

mixture
25th Jun 2013, 15:25
No, not moaning, just remarking on how much more complicated Mac stuff is.
It confirms that I was right not to go further down that path. I'm not clever enough.

What are you on about ? :ugh:

Mac OS X ... as used by your average Joe, i.e used via the graphical interface is not complicated. It is most certainly not more complicated than Windows, and infact, I would even say it is easier and simpler than Windows at graphical level.

If you're messing around at command line level then all bets are off, because there is an implied understanding from both sides (OS X and Windows) that you know what you are doing. You can't really go around saying one command line is more complicated than the other, because by their nature, CLIs have a learning curve and are as complex or as simple as you want them to be, and are prepared to put in the time and effort to learn how to use them. Personally I find the Windows command line a right pain in the backside !

You also have to bear in mind that SpringHeeledJack presented us with a bit of an edge case. My solution was to provide an answer using built-in tools. I'm sure you could find apps on the App Store (or elsewhere on the internet) that would have done the same job via clicks of the mouse (such as the example posted by Milo).

Milo Minderbinder
25th Jun 2013, 15:36
on a personal point of view I find the Microsoft command line a lot easier to remember that any Unix variant......but then again I do my damnedest to avoid using either.
Personally I place the ability to remember command line switches as a skill usuallybest known by those who wait at the end of railway platforms with biros and notebooks..........if I can find a graphical tool, I'll use it. Hence my last post. Someone has to try to make it easy....

Keef
25th Jun 2013, 15:43
What are you on about ? :ugh:


I'm on about how glad I am I don't have a Mac. I suppose I'm just not an average Joe.

Feel free to defend Macs by insulting me, but I still find the one-line command for Windows a lot simpler.

mixture
25th Jun 2013, 16:40
When did I insult you ?

I was merely pointing out the obvious that you can't exactly go round calling one command line more complicated than another.

Mac the Knife
25th Jun 2013, 17:36
Good explanation - http://staff.washington.edu/dittrich/misc/faqs/unix.rename.wildcard (http://staff.washington.edu/dittrich/misc/faqs/unix.rename.wildcard)

Mac

:ok:

SpringHeeledJack
26th Jun 2013, 17:11
Great.....I was gone from the thread for a day and Keefs been computarily insulted and every single file on my whole computer has been turned into a jpg :) I jest of course. Thanks to those who wrote the script for Terminal, but it gives me the heebie-geebies just looking at it. It WOULD be a solution, but I'm nervous of getting the spaces correct (1 or more spaces?) and certain of the annotations are unknown to me in terms of where I'd find them (Finder/special characters?) and on and on. I did look at some of the renaming programs, but there seems not to be an obvious link with changing file extensions. I've only slept 3hrs in the last 24, so perhaps I'm too jaded to see, it's so true about extreme tiredness mimicking being drunk. Prost!:8



SHJ

Mac the Knife
26th Jun 2013, 18:51
Looks like ScoobyRenamer - SkoobySoft - Skooby Renamer (http://www.skoobysoft.com/renamer/renamer.html) - will do the trick

Mac

:ok:

Edited to add: Oops, its not free - will look further.

Windy Militant
26th Jun 2013, 21:35
What OS do you have? I think anything with OS X 10 comes with the Automater application which allows you to set up this sort of thing.
I've used it a while ago but am a bit hazy as to how it works, but it can't be that bad if I managed to get it to work.
Like wot they said make a copy of some of the files to try it out and when happy with that do it for real.

MacBoero
26th Jun 2013, 22:31
Automator is pretty straight forward...

(1) Fire up Automator
http://oi44.tinypic.com/osaao0.jpg

(2) Select all the files you want to rename and drag them into the workflow...
http://oi41.tinypic.com/5wjlw4.jpg

(3) Ensure "Actions" is selected and type "rename" into the search box...
http://oi39.tinypic.com/2vrxysk.jpg

(4) Drag the "Rename finder items" action into the workflow area below the list of files. You'll get a dialogue asking you if you want to create new files (copies) or alter the originals. You can choose either, in which case you'll need to select a destination folder. For this instruction, I'll choose "Don't Add", i.e. Don't add a copy function into the workflow...
http://oi42.tinypic.com/2n66hyd.jpg

(5) In the action block, you'll need to change the "Add Date or Time" drop down to "Replace Text"...
http://oi41.tinypic.com/ogxd00.jpg

(6) Enter details of the wrong file extension to be found in the file names, and the replacement extension you want...
http://oi39.tinypic.com/ml7eya.jpg

(7) Click the "Run" button...
http://oi43.tinypic.com/n15lbk.jpg

(8)Hopefully you have a nice set of green ticks and the file names have been changed as you wanted. You can check what the Rename action has done by clicking the "Results" button...
http://oi43.tinypic.com/2wo9jbd.jpg


Good luck! :ok:

SpringHeeledJack
27th Jun 2013, 16:17
Thankyou everyone, the .jpg's have been re-instated to their correct place. The world can breath easily again :rolleyes:;) However, the developer actually DID get back to me, though it took a week and there was a method to repair my fat-fingered IT ignorance, but to be honest it wouldn't have been obvious to me at all had it not been pointed out. I was getting ready to try both Terminal and Automator at the weekend when I had some time to fully explore the methods described. Thanks and obrigado :ok:



SHJ

MacBoero
27th Jun 2013, 16:18
De nada!:ok:

mixture
27th Jun 2013, 16:24
SpringHeeledJack,

No worries, happy to hear you got your porn stash back in order ! :}

SpringHeeledJack
27th Jun 2013, 16:42
It was terrible, I didn't know my left (hand) from my right :} In this case it was concerning 1000's of photos taken over the last 5 years that are finally getting sorted through and collated and, and, and.....



SHJ