[LAU] More spaces in filenames [was: No batch processing on Linux?]

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <linux-audio-user@...>
Date: Tuesday, October 5, 2010 - 11:59 am

On Sat, Sep 25, 2010 at 8:49 AM, Marc Groenewegen
wrote:

The if [ $oldname != $newname ] bit is nice; avoids errors with mv.

You could also get rid of other nasties with

newname=`echo $f | tr ' ' '_' | tr -d '[{}(),\!]' | tr -d "\'" | sed
's/_-_/_/g'`

But if directories have spaces as well, one solution is (from somewhere
on the Arch Linux forums)

#! /bin/bash
# remove spaces from directory names and contents recursively

IFS=$'\n'

function cleanup {
if [ -d "$1" ];
then
DIR="$1"
cd "$DIR"
fi

pwd

for f in `find . -maxdepth 1`; do
[ -d "$f" -a "$f" != "." ] && (cleanup "$f")

file=$(echo $f | tr ' ' '_' )
[ -e "$f" ] && [ ! -e "$file" ] && mv "$f" "$file"

done
[ "$DIR" ] && cd - > /dev/null
}
cleanup .

unset IFS

Even better is this (from perlmonks.org/?node_id=27739)

find2perl . -depth -eval 'my $o=$_; tr/_/ /; -e or rename $o,$_ or warn
"cannot rename $o to $_: $!"' | perl

Does the lot in one hit.
_______________________________________________
Linux-audio-user mailing list
Linux-audio-user@lists.linuxaudio.org
http://lists.linuxaudio.org/listinfo/linux-audio-user

Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
Re: [LAU] No batch processing on Linux?, Marc Groenewegen, (Sat Sep 25, 6:50 am)
[LAU] More spaces in filenames [was: No batch processing on ..., M Watts, (Tue Oct 5, 11:59 am)
Re: [LAU] No batch processing on Linux?, Arve Barsnes, (Sat Sep 25, 7:39 am)
Re: [LAU] No batch processing on Linux?, Hartmut Noack, (Sat Sep 25, 1:05 pm)
Re: [LAU] No batch processing on Linux?, Jeremy Jongepier, (Mon Sep 27, 1:33 pm)
Re: [LAU] No batch processing on Linux?, Paul Davis, (Mon Sep 27, 1:51 pm)
Re: [LAU] No batch processing on Linux?, Alexandros Diamantidis, (Tue Sep 28, 8:35 pm)
Re: [LAU] No batch processing on Linux?, Paul Davis, (Tue Sep 28, 10:59 pm)
Re: [LAU] No batch processing on Linux?, Patrick Shirkey, (Mon Sep 27, 2:25 pm)
Re: [LAU] No batch processing on Linux?, Joel Roth, (Mon Sep 27, 5:36 pm)