Register
It is currently Sat Sep 20, 2014 2:00 pm

Recursively shorten file names


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Sat Jan 17, 2009 4:22 pm   

Joined: Sat Jan 17, 2009 4:08 pm
Posts: 2
I have a large library of soundfiles that has to be converted to maximum 16 characters (extension not included).

They are so many so truncation has to be automatic and no files in the same directory my have the same filename after truncation.

Any good script doing something like this?

Example:
Roland tr-808 clean mono bd.wav
Roland tr-808 clean mono sd.wav
Roland tr-808 clean mono cp.wav

Would preferably be converted to something like:
RolandTr-808ClBd.wav
RolandTr-808ClSd.wav
RolandTr-808ClCp.wav
(the only text that was unique in each file is kept)

But this would be alright too:
Roland tr-80#001.wav
Roland tr-80#002.wav
Roland tr-80#003.wav


Top
 Profile  
 PostPosted: Sat Jan 17, 2009 7:29 pm   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Does all files follow a specific format or can they suddenly contain diffrent information, like skipping the mono or not contain tr-808?

if all you need is to seperate the files with a decending number sequence this is quite simple.
Code:
x=0
for i in *; do
   if [ $x -lt 100 ]; then
       if [ $x -lt 10 ]; then
          $number="00${x}"
       else
          $number="0${x}"
       fi
   fi
   newfilename=$(echo "RolandTr-808#$number")
   mv "$i" "$newfilename"
   let x=x+1
done


This will work for quite alot of files, but will only add 0's up to 100, you can add more if's and stuff if you want but principly this is how it works.

If the files changes and needs to be designated something other then RolandTr-808 it's a whole new problem and I would say we need more information on how the files is named.

ps. the above script doesn't care what the file was named before, it will just be named as said above with a trailing number. ds.
ps2. I haven't tested this :P I would recommend putting mv line in an echo "<line>" and dry-running this before doing it live :P ds.
Best regards
Fredrik Eriksson


Top
 Profile  
 PostPosted: Mon Jan 19, 2009 5:04 pm   

Joined: Sat Jan 17, 2009 4:08 pm
Posts: 2
Thanks a lot. That could be a good start but it's not really what I need.

However I found an alternative solution using ordinary(?) software for OS X.
So my problem is solved by other means.

-----

Anyways for anyone curious here are more details:

It needs to handle any name format.

One group of files may look like this:
Roland tr-808 clean mono bd.wav
Roland tr-808 clean mono sd.wav
Roland tr-808 clean mono cp.wav

Another like this:
Sci Fi Effects from the fifties 0001.wav
Sci Fi Effects from the fifties 0002.wav
Sci Fi Effects from the fifties 0003.wav

And maybe like this
Movie sample recording A Big car crash.wav
Movie sample recording B Helicopter.wav
Movie sample recording C Mr Spock saying something.wav

Ideally only parts of the name that are identical within a group would be shortened to start with. Keeping as much unique information as possible.

M#001Big car cra.wav - GOOD
Movie sample#001.wav - NOT GOOD

I guess some magic RegExp would do this but that's way out of my league.


Top
 Profile  
 PostPosted: Tue Jan 20, 2009 2:34 am   

Joined: Mon Nov 17, 2008 7:25 am
Posts: 221
Well that's the issue... if the files doesn't even come close to each other then a regexp is insanely tricky to write for 100% usage.
Ofc you could do alot of "cases" but to match all kinds of variants but it could become very long and not very accurate.

Best regards
Fredrik Eriksson


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP