Go Back  PPRuNe Forums > Misc. Forums > Computer/Internet Issues & Troubleshooting
Reload this Page >

Batch renaming file extensions (Mac)


Notices
Computer/Internet Issues & Troubleshooting Anyone with questions about the terribly complex world of computers or the internet should try here. NOT FOR REPORTING ISSUES WITH PPRuNe FORUMS! Please use the subforum "PPRuNe Problems or Queries."

Batch renaming file extensions (Mac)

Old 24th June 2013 | 21:38
  #1 (permalink)  
Thread Starter
 
Joined: Jan 2008
Posts: 3,156
Likes: 113
From: There and here
Snoop Batch renaming file extensions (Mac)

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 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
SpringHeeledJack is online now  
Reply
Old 24th June 2013 | 22:14
  #2 (permalink)  
 
Joined: Aug 2002
Posts: 3,663
Likes: 0
From: Earth
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.

Last edited by mixture; 24th June 2013 at 22:18.
mixture is offline  
Reply
Old 25th June 2013 | 07:40
  #3 (permalink)  
Thread Starter
 
Joined: Jan 2008
Posts: 3,156
Likes: 113
From: There and here
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
SpringHeeledJack is online now  
Reply
Old 25th June 2013 | 08:34
  #4 (permalink)  
 
Joined: Apr 2008
Posts: 565
Likes: 21
From: Passed away on Sept 6th
Originally Posted by SpringHeeledJack
...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?
jimtherev is offline  
Reply
Old 25th June 2013 | 08:40
  #5 (permalink)  
 
Joined: Aug 2002
Posts: 3,663
Likes: 0
From: Earth
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
Code:
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):
Code:
tar cvf random_25June013.tar random/
Code:
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 …
Code:
cd random
•enter the following……
Code:
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 !

Last edited by mixture; 25th June 2013 at 09:27.
mixture is offline  
Reply
Old 25th June 2013 | 11:31
  #6 (permalink)  

Official PPRuNe Chaplain
 
Joined: Apr 2001
Posts: 3,498
Likes: 0
From: Witnesham, Suffolk
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.
Keef is offline  
Reply
Old 25th June 2013 | 12:02
  #7 (permalink)  
 
Joined: Aug 2002
Posts: 3,663
Likes: 0
From: Earth
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

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

then...

Code:
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.

Last edited by mixture; 25th June 2013 at 12:13.
mixture is offline  
Reply
Old 25th June 2013 | 12:59
  #8 (permalink)  
 
Joined: Aug 2002
Posts: 3,663
Likes: 0
From: Earth
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

Last edited by mixture; 25th June 2013 at 13:14.
mixture is offline  
Reply
Old 25th June 2013 | 15:03
  #9 (permalink)  

Official PPRuNe Chaplain
 
Joined: Apr 2001
Posts: 3,498
Likes: 0
From: Witnesham, Suffolk
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.
Keef is offline  
Reply
Old 25th June 2013 | 15:20
  #10 (permalink)  
 
Joined: Jan 2012
Posts: 2,173
Likes: 0
From: .
3 Easy Ways to Batch Rename Files on the Mac | Mactuts+
Milo Minderbinder is offline  
Reply
Old 25th June 2013 | 15:25
  #11 (permalink)  
 
Joined: Aug 2002
Posts: 3,663
Likes: 0
From: Earth
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 ?

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).

Last edited by mixture; 25th June 2013 at 15:34.
mixture is offline  
Reply
Old 25th June 2013 | 15:36
  #12 (permalink)  
 
Joined: Jan 2012
Posts: 2,173
Likes: 0
From: .
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....
Milo Minderbinder is offline  
Reply
Old 25th June 2013 | 15:43
  #13 (permalink)  

Official PPRuNe Chaplain
 
Joined: Apr 2001
Posts: 3,498
Likes: 0
From: Witnesham, Suffolk
Originally Posted by mixture
What are you on about ?
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.
Keef is offline  
Reply
Old 25th June 2013 | 16:40
  #14 (permalink)  
 
Joined: Aug 2002
Posts: 3,663
Likes: 0
From: Earth
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.
mixture is offline  
Reply
Old 25th June 2013 | 17:36
  #15 (permalink)  

Plastic PPRuNer
25 Anniversary
 
Joined: Sep 2000
Posts: 1,902
Likes: 0
From: Rochechouart, France
Good explanation - http://staff.washington.edu/dittrich/misc/faqs/unix.rename.wildcard

Mac

Mac the Knife is offline  
Reply
Old 26th June 2013 | 17:11
  #16 (permalink)  
Thread Starter
 
Joined: Jan 2008
Posts: 3,156
Likes: 113
From: There and here
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!



SHJ
SpringHeeledJack is online now  
Reply
Old 26th June 2013 | 18:51
  #17 (permalink)  

Plastic PPRuNer
25 Anniversary
 
Joined: Sep 2000
Posts: 1,902
Likes: 0
From: Rochechouart, France
Looks like ScoobyRenamer - SkoobySoft - Skooby Renamer - will do the trick

Mac



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

Last edited by Mac the Knife; 26th June 2013 at 18:52.
Mac the Knife is offline  
Reply
Old 26th June 2013 | 21:35
  #18 (permalink)  
 
Joined: Oct 1999
Posts: 568
Likes: 0
From: Swindon, Wilts,UK
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.
Windy Militant is offline  
Reply
Old 26th June 2013 | 22:31
  #19 (permalink)  
15 Anniversary
 
Joined: Jan 2008
Posts: 300
Likes: 0
From: London, England
Automator is pretty straight forward...

(1) Fire up Automator


(2) Select all the files you want to rename and drag them into the workflow...


(3) Ensure "Actions" is selected and type "rename" into the search box...


(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...


(5) In the action block, you'll need to change the "Add Date or Time" drop down to "Replace Text"...


(6) Enter details of the wrong file extension to be found in the file names, and the replacement extension you want...


(7) Click the "Run" button...


(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...



Good luck!
MacBoero is offline  
Reply
Old 27th June 2013 | 16:17
  #20 (permalink)  
Thread Starter
 
Joined: Jan 2008
Posts: 3,156
Likes: 113
From: There and here
Thankyou everyone, the .jpg's have been re-instated to their correct place. The world can breath easily again 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



SHJ
SpringHeeledJack is online now  
Reply

Thread Tools
Search this Thread

Contact Us - Archive - Advertising - Cookie Policy - Privacy Statement - Terms of Service

Copyright © 2026 MH Sub I, LLC dba Internet Brands. All rights reserved. Use of this site indicates your consent to the Terms of Use.