REXX equivalent in (Ubuntu) Linux?

William O'Higgins Witteman william.ohiggins-H217xnMUJC0sA/PxXw9srA at public.gmane.org
Fri May 21 14:38:11 UTC 2010


On Fri, May 21, 2010 at 10:17:03AM -0400, Stephen wrote:
>I want to do a big rename of files on my Linux system.
>
>I have ripped a large number of CD's, and the filenames start with
>the track number. But they go 1,2,3 ...10,11,12
>
>When my PS3 accesses my (Linux) media server, it sees these as
>10,11,12,1,2....
>
>So to get the right order I want to change the files to 01,02,03...
>
>
>The files are in directories:
>
>/home/stephen/music/*artist*/*album*/filenames
>
>What should I look at?
>
>BASH???

If you have a favourite scripting language, use that.  For instance, in
Python (my favoured tool) you would use the os module to walk the
filesystem and generate sensible filenames (with padded numerical values).

Example Pythonic pseudocode (no time to write/test a real script this
morning (sorry)):

import os

basedir = "/home/stephen/music"

for root, directory, file in os.path.walk(basedir):
  for artist in directory:
    for album in artist:
      trackdir_location = os.path.join(root,os.path.join(directory,os.path.join(artist,album)))
      tracks = os.listdir(trackdir_location)
      for track in tracks:
        " Assuming the files are called ##.ogg or somesuch
        tracknameparts = track.split(".ogg")
        newtrackname = artist + "_" + album + "_" + str("%\d2",int(tracknameparts[0]))
        os.rename(os.path.join(trackdir_location,track),os.path.join(trackdir_location,newtrackname))

That's off the top of my head, but it is at least an approach.  Remember
to make a copy to test on :-)

Good luck!
-- 

yours,

William

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 190 bytes
Desc: Digital signature
URL: <http://gtalug.org/pipermail/legacy/attachments/20100521/5b0c542f/attachment.sig>


More information about the Legacy mailing list