REXX equivalent in (Ubuntu) Linux?

Fabio FZero fabio.fzero-Re5JQEeQqe8AvxtiuMwx3w at public.gmane.org
Fri May 21 14:57:48 UTC 2010


I have to say this: os.path.walk saved my life a couple of times when I
worked with mobile content.

I used to receive lots of video files without any naming convention and a
CSV which listed which file had which format(s). Using a combination of
os.path.walk with the CSV python module, I sorted out this mess two times a
week in less than one minute.

I love you os.path.walk. If you were a girl, I would marry you.

xoxo
FZero

On Fri, May 21, 2010 at 10:38, William O'Higgins Witteman <
william.ohiggins-H217xnMUJC0sA/PxXw9srA at public.gmane.org> wrote:

> 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
>
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.10 (GNU/Linux)
>
> iD8DBQFL9prTHQtmiuz+KT8RAnP2AJ40UUYxLeL+I5G+dfCLSmbrC+xU4gCfdyiG
> Db/w4RBp+siANnsEDqcCQ10=
> =NQzY
> -----END PGP SIGNATURE-----
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://gtalug.org/pipermail/legacy/attachments/20100521/9b087b3c/attachment.html>


More information about the Legacy mailing list