Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Mac OS X > unix guru help

unix guru help
Thread Tools
Senior User
Join Date: Apr 2001
Location: Palo Alto, CA
Status: Offline
Reply With Quote
Sep 23, 2003, 01:07 AM
 
I am looking for a quick way to do the following:

append ".mp3" to all the files in a specific folder that do not already end in ".mp3" (right now they are being read as text files.

Note that within the folder there are tons of nested subfolders...

Is there any easy way to do this?
     
Dedicated MacNNer
Join Date: Sep 2003
Location: Pittsburgh, Pennsylvania
Status: Offline
Reply With Quote
Sep 23, 2003, 01:48 AM
 
Originally posted by barbarian:
I am looking for a quick way to do the following:

append ".mp3" to all the files in a specific folder that do not already end in ".mp3" (right now they are being read as text files.

Note that within the folder there are tons of nested subfolders...

Is there any easy way to do this?
I have three words for you

Perl
Regular Expressions

write a recursive function that goes through all the directories, and it checks if the file ends in .mp3, if not append it. I'm not the best at regular expressions, but about 10min of googling and 10min of coding and you should be set.

Nate
     
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Sep 23, 2003, 02:35 AM
 
Here's a simple approach that works OK on my tests. (Standard warning: check it out on a sample directory first!) It just uses some of the inbuilt goodness of zsh. At a terminal prompt ( % ) enter:
Code:
zsh
Then enter
Code:
for file in **/*~*.mp3(.)
You should see a "for>" symbol. Enter
Code:
mv $file $file.mp3
and you're done. "exit" will get you out of zsh and you're back where you started, but hopefully without the renaming problem any more.

Best of luck,
Paul (who knows all too well that this could be done with find and exec, and maybe xargs and blah blah blah: but what fun would that be?)
(Last edited by Paul McCann; Sep 23, 2003 at 02:42 AM. )
     
Mac Elite
Join Date: Oct 2000
Location: Seattle
Status: Offline
Reply With Quote
Sep 24, 2003, 06:01 AM
 
You have an apple script that does that

look in /Library/Scripts/Finder Scripts

run the one called "Add to File Names.scpt"



cheers
You can take the dude out of So Cal, but you can't take the dude outta the dude, dude!
     
Mac Enthusiast
Join Date: Apr 2001
Status: Offline
Reply With Quote
Sep 24, 2003, 09:37 PM
 
Originally posted by barbarian:
I am looking for a quick way to do the following:

append ".mp3" to all the files in a specific folder that do not already end in ".mp3" (right now they are being read as text files.

Note that within the folder there are tons of nested subfolders...

Is there any easy way to do this?

IMHO the best way is to go to version tracker and download one of the many apps or contextual menus for the finder that does this for you.

     
Mac Enthusiast
Join Date: Jul 2002
Location: Leiden, Netherlands
Status: Offline
Reply With Quote
Sep 25, 2003, 01:12 AM
 
Originally posted by Paul McCann:

Code:
mv $file $file.mp3
mv "$file" "$file".mp3
will work a lot better with file that contains a space in their filename.
     
Mac Enthusiast
Join Date: Nov 2001
Location: Adelaide, South Australia
Status: Offline
Reply With Quote
Sep 25, 2003, 08:36 PM
 
Originally posted by Ludovic Hirlimann:
mv "$file" "$file".mp3
will work a lot better with file that contains a space in their filename.
Yes indeed: thanks for the correction. One day I'll remember that people really do use spaces in filenames.

Cheers,
Paul
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 08:36 AM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2