Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Renaming music files
- X-seq: zsh-users 18853
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: Renaming music files
- Date: Sun, 25 May 2014 19:31:59 +0100
- In-reply-to: <20140525122645.GB3794@solfire>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <20140525122645.GB3794@solfire>
On Sun, 25 May 2014 14:26:45 +0200
meino.cramer@xxxxxx wrote:
> Gentoo/Gentoo - Sound of a UNIX System/Gentoo - Sound of a UNIX System - 01 Eternal Boot.flac
> Gentoo/Gentoo - Sound of a UNIX System/Gentoo - Sound of a UNIX System - 02 Devine UDEV.flac
> Gentoo/Gentoo - Sound of a UNIX System/Gentoo - Sound of a UNIX System - 03 Nvidias Light.flac
>
> To save space on the display I use to rename the directories and files
> to this (using zmv):
>
> Gentoo/Sound of a UNIX System/01 Eternal Boot.flac
> Gentoo/Sound of a UNIX System/02 Devine UDEV.flac
> Gentoo/Sound of a UNIX System/03 Nvidias Light.flac
>
> and use detox afterwards to get rid of the spaces in names.
>
> Is there any way to automate this by instruct zmv to throw away
> anything, which does not change and only keep the changing part?
Not using zmv, and not to automate *anything* that doesn't change ---
that's way too general for a computer to understand, unless you're
prepared to wait a few decades. You'll end up removing repeated
letters, for example, or odd words that happen to occur in different
parts of the name.
However, in the form you've shown above you can do something like the
following. Comment out the print and uncomment the mv. You can make it
more general, but you'll have to find out any other ways significant
repetitions can occur, and any other ways the repeated segments can be
joined.
local seppat="[[:space:]]##[-_][[:space:]]##"
local seg f newf
local -A strip
local -a match mbegin mend
for f in **/*(.); do
# Record bits we're going to strip
strip=()
newf=
for seg in ${(s./.)f}; do
# First see if there's anything we can strip.
while [[ ${#strip} -ne 0 && $seg = (${(kj.|.)~strip})${~seppat}(#b)(*) ]]
do
seg=$match[1]
done
# Allow what's left to be stripped.
strip[$seg]=1
newf=${newf:+$newf/}$seg
done
if [[ $newf != $f ]]; then
print "Would move from:\n$f\nto:\n$newf"
# mv -- $f $newf
fi
done
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author