[nSLUG] Removing spaces from file names - note, long lines

Stephen Gregory nslug at kernelpanic.ca
Wed Nov 12 21:54:36 AST 2014


On Wed, Nov 12, 2014 at 8:24 PM, Vlado Keselj <vlado at dnlp.ca> wrote:
>
> #!/usr/bin/perl
> # Author: Vlado Keselj 2009-14 last update 2014-04-25
> # Change file names to safe names (e.g., space to _)
>
> for my $fnold (@ARGV) {
>     my $fnnew = $fnold;
>
>     local $_ = $fnnew; s/ +- +/-/g;
>     s/''+/--/g; s/'/-/g; s/[[(<{]/_-/g; s/[])>}]/-_/g;
>     s/[,:;]\s*/--/g; s/&/and/g; s/ /_/g;
>     s/__+/_/g; s/---+/--/g;
>     s/\xE2\x80\x99/-/g; # Single right quote
>     s/(=|[^\w.-])/"=".uc unpack("H2",$1)/ge;
>     $fnnew=$_;


<insert joke about email corrupted by line noise here>

That seems to handle most of the annoyances in filenames, but does it
handle files that start with a [-$*] or similar special?

-- 
sg


More information about the nSLUG mailing list