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

Vlado Keselj vlado at dnlp.ca
Wed Nov 12 21:24:21 AST 2014

Interesting that so many people need this similar utility.  I have been 
using my Perl script fix-file-names.pl.  I tried to fix the file names in 
a way that look reasonable to me, and yet not to loose too much 

# 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;

    if ($fnnew eq $fnold) { print "$fnnew \t\tthe same file name kept!\n" }
    else {
	if (-e $fnnew) { die "$fnnew already exists!" }
	print "$fnold \t-> $fnnew\n";
	rename($fnold,$fnnew) or die;


On Wed, 12 Nov 2014, Oliver Doepner wrote:

> I use exiftool because it can deal with video files as well as picture files:
> http://dev.exiv2.org/projects/exiv2/wiki/How_does_Exiv2_compare_to_Exiftool
> http://www.exiv2.org/manpage.html
> On Wed, Nov 12, 2014 at 3:29 PM, Jack Warkentin <jwark at bellaliant.net> wrote:
>       Hi Everybody
>       exiv2 ( http://www.exiv2.org/ ) is another command line utility for extracting and writing exif data to/from
>       jpeg image files. I use it for writing location and caption information into the pictures I have taken, and
>       then displaying the information back in a nice format. On Debian, it is available as a package with that
>       name.
>       Regards
>       Jack
>       Mike Spencer wrote:
>             Oliver Doepner<odoepner at gmail.com>  wrote:
>                   Regarding moving photo files, I use a script that utilizes exiftool
>                   to determine year and month the photo (or video) was taken and moves
>                   it to a yyyy/mm folder:
>                   https://odoepner.wordpress.com/2014/01/11/organize-image-and-video-files-by-creation-date-with-exiftool/
>             Interesting.  I've used wrjpgcom(1) to add metadata to jpegs although
>             that feature of jpeg seems to be little used elsewhere.
>             I don't have exiftool (just fetched it from the net) although I see
>             from strings(1) that the date for many photos is there in a header
>             field of some kind.  I gather, from glancing over the EXIF standard
>             (MEGO), that EXIF is built on top of TIFF?  I once commenced trying to
>             beat up the TIFF libs with a view to writing my own image manipulation
>             code.  It wasn't very long before I decided that I didn't care enough
>             about it to grovel through all the defines, typedefs and other
>             indirection to the required extent.
>             So I have a new tool to play with, thanks.  Although I'm not sure I'll
>             have much need for most of the capabilities.
>             - Mike
>       --
>       Jack Warkentin, phone 902-404-0457, email jwark at bellaliant.net
>       39 Inverness Avenue, Halifax, Nova Scotia, Canada, B3P 1X6
>       _______________________________________________
>       nSLUG mailing list
>       nSLUG at nslug.ns.ca
>       http://nslug.ns.ca/mailman/listinfo/nslug
> --
> Oliver Doepner
> Software Engineer
> http://oliver.doepner.net/

More information about the nSLUG mailing list