summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJérémy Zurcher <jeremy@asynk.ch>2011-06-14 10:56:44 +0200
committerJérémy Zurcher <jeremy@asynk.ch>2011-06-14 10:56:44 +0200
commitaddaf359b5ef46fd17775e3e587b77389b9f1ae2 (patch)
tree5c078638fda5b100322a1e9aa264f3d667fa0af7
parent1afd50d265ed70e9db1d79c43c1ce3003efa7410 (diff)
downloadbin-addaf359b5ef46fd17775e3e587b77389b9f1ae2.zip
bin-addaf359b5ef46fd17775e3e587b77389b9f1ae2.tar.gz
add spaceTo_
-rwxr-xr-xspaceTo_34
1 files changed, 34 insertions, 0 deletions
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);