From addaf359b5ef46fd17775e3e587b77389b9f1ae2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Tue, 14 Jun 2011 10:56:44 +0200 Subject: add spaceTo_ --- spaceTo_ | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100755 spaceTo_ diff --git a/spaceTo_ b/spaceTo_ new file mode 100755 index 0000000..01ba9da --- /dev/null +++ b/spaceTo_ @@ -0,0 +1,34 @@ +#! /usr/bin/perl + +# /bin/sh : NEW=`ls | sed s/\ /_/g | sed s/_-_/_/g ` + +sub proceed{ + my $dir=shift; + my $prefix=shift; + opendir(DIRHANDLE,$dir) || die "Cannot open dir $dir"; + while ($name=readdir(DIRHANDLE)){ + if($name =~m/^\./){ + next; + } + my $ustring = "\x{b4}"; + my $new = $name; + $new =~ s/ /_/g; + $new =~ s/'/_/g; + $new =~ s/[\[\]]/_/g; + $new =~ s/$ustring/_/g; + $new =~ s/\._/_/g; + $new =~ s/_+\./\./g; + $new =~ s/[_-](-*_*)+/_/g; + $new =~ s/\\/-/g; + $new =~ s/\\/-/g; + if(defined($prefix)){ + $new =~ s/^$prefix//g; + } + if ($name ne $new) { + rename($name, $new) || die "Unable to rename $name in $new."; + } + } + closedir(DIRHANDLE); +} + +proceed(".", shift); -- cgit v1.1-2-g2b99