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

Eugene Cormier eugene.cormier at gmail.com
Wed Nov 12 22:28:02 AST 2014


Hey Oliver, yours is much more useful, I was really just respond to the
subject of these emails without reading the whole thread :)

E
On Wed, Nov 12, 2014 at 10:22:42PM -0400, Oliver Doepner wrote:
>    I guess it sounds like I am tooting my own horn here, but ...
>    My script recursively cleans up directory and file names, byreplacing
>    all characters with an underscore that are not alphanumeric,
>    underscore, dot or dash. It also works for weird stuff like newlines,
>    wildcards etc in filenames. It only requires bash, find and mv.
>    And it never overwrites any files that happen to have the same
>    "sanitized" filename (using --backup=numbered).
>    [1]http://odoepner.wordpress.com/2011/10/13/bash-script-to-recursively-
>    sanitize-folder-and-file-names/
>    Please let me know if/how the same thing can be done in a simpler way.
>    Vlado's script requires perl (acceptable) but has lots of
>    unecessarily(?) complicated regexes.
>    Eugene's one-liner only removes spaces and only for files in the
>    current folder.
>    Jack's script only works for single regular files and is quite verbose,
>    compared to Eugene's one-liner.
>    Thanks
>    Oliver
> 
>    On Wed, Nov 12, 2014 at 9:54 PM, Stephen Gregory
>    <[2]nslug at kernelpanic.ca> wrote:
> 
>      On Wed, Nov 12, 2014 at 8:24 PM, Vlado Keselj <[3]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
> 
>    _______________________________________________
>    nSLUG mailing list
>    [4]nSLUG at nslug.ns.ca
>    [5]http://nslug.ns.ca/mailman/listinfo/nslug
> 
>    --
>    Oliver Doepner
>    Software Engineer
>    [6]http://oliver.doepner.net/
> 
> References
> 
>    1. http://odoepner.wordpress.com/2011/10/13/bash-script-to-recursively-sanitize-folder-and-file-names/
>    2. mailto:nslug at kernelpanic.ca
>    3. mailto:vlado at dnlp.ca
>    4. mailto:nSLUG at nslug.ns.ca
>    5. http://nslug.ns.ca/mailman/listinfo/nslug
>    6. http://oliver.doepner.net/

> _______________________________________________
> nSLUG mailing list
> nSLUG at nslug.ns.ca
> http://nslug.ns.ca/mailman/listinfo/nslug


-- 
Eugene Cormier
---------------
Full-time Instructor
Acadia University
www.eugenecormier.com
eugenecormier at gmail.com
Office: Denton Hall Rm.235
Office Hours: Monday & Wednesday 10:30-11:30 (or by appointment)
Phone: (902) 585-1329


---------------
Statement of Confidentiality
This message (including attachments) may contain confidential or
privileged information intended for a specific individual or
organization. If you have received this communication in error, please
notify the sender immediately. If you are not the intended recipient,
you are not authorized to use, disclose, distribute, copy, print or rely
on this email, and should promptly delete this email from your entire
computer system.



More information about the nSLUG mailing list