Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 14 Jan 2002 23:35:08 +0200
From:      Giorgos Keramidas <keramida@freebsd.org>
To:        "J.S." <johann@broadpark.no>
Cc:        freebsd-questions@freebsd.org
Subject:   Re: Filename tool?
Message-ID:  <20020114213507.GG31045@hades.hell.gr>
In-Reply-To: <20020114205116.3183e89a.johann@broadpark.no>
References:  <20020114205116.3183e89a.johann@broadpark.no>

next in thread | previous in thread | raw e-mail | index | archive | help

--5CUMAwwhRxlRszMD
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On 2002-01-14 20:51:15, J.S. wrote:
> Hi.
>
> I have large collection of files within many branches of filetypes, and
> before they enter my 'main' collection I have to manually change the
> filenames so that I am satisfied with the way they are.
>
> E.g.:
>
> Artist_-_Dis'z_Deh_Name_Of_My_Song_(My_Remix)-GROUP.mp3
>
> I rename to:
>
> artist-disz_deh_name_of_my_song-my_remix-group.mp3
>
> Is that 100% POSIX compliant or what? =3D)
>
> Anyway, I was wondering if there existed a tool which can organize both
> files and directories the same way I do. Perhaps even better?

I recently got a cdrom in my snail mail with several dozens of mp3
collections.  The files were all in that style so popular among the
Windows world, with spaces between words, parentheses, and a ton of
other characters that would make my life more difficult.

Your friend is your FreeBSD base-system.  It has all the tools you
need to make scripts like:

	#!/bin/sh

	for fname in `find . -depth` ;do
		# strip all non alpha/digit/space/./-/_ characters
		fa=3D"`echo \"${fname}\" | sed -e 's/[^ [:alpha:][:digit:].-_]//g'`"
		# replace spaces with _
		fb=3D"`echo \"${fa}\" | sed -e 's/[[:space:]][[:space:]]/_/g'`"
		# lowercase all
		fc=3D"`echo \"${fb}\" | tr A-Z a-z`"
		# ...
		# ... do what other stuff you want with the filename
		# ...
		mv "${fname}" "${fc}"
	done

Of course, while you're testing a script like the one above, you might
want to use "echo mv" instead of "mv".  This way you can verify that
the mv(1) command will rename the file to a name that you like, and
then run the same script without "echo" to actually do the rename.

--=20
Giorgos Keramidas . . . . . . . . . keramida@{ceid.upatras.gr,freebsd.org}
FreeBSD Documentation Project . . . http://www.freebsd.org/docproj/
FreeBSD: The power to serve . . . . http://www.freebsd.org/

--5CUMAwwhRxlRszMD
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (FreeBSD)

iD8DBQE8Q08L1g+UGjGGA7YRAvgDAJ9zmOqNAdGn6KUoQYwjWgHJa1zW/ACghe5I
qqz+HbnYlORd+uhZ76nowFs=
=SwNu
-----END PGP SIGNATURE-----

--5CUMAwwhRxlRszMD--

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020114213507.GG31045>