Anytime you have to copy or more files from Windows to Unix/Linux you'll 
pretty much always run into file names with spaces in them (why in the 
world that's permitted, I do not know, but, hey, it's Windows and 
doesn't have to make any sense).

Here's a little utility that renames-in-place, substituting spaces with 
underscores -- work great, just execute it in any directory and problem 
solved (including Windows directory names with space in them!). It's 
called blank-rename:

#!/bin/bash
#
#    This program is free software; you can redistribute it and/or
#    modify it under the terms of version 2 of the GNU General
#    Public License as published by the Free Software Foundation.
#
#    This program is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
#    General Public License for more details.
#
#    You should have received a copy of the GNU General Public
#    License along with this program; if not, write to the Free
#    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
#    MA 02111-1307, USA.

ONE=1                # For getting singular/plural right (see below).
number=0            # Keeps track of how many files actually renamed.
FOUND=0                # Successful return value.

for filename in *        # Traverse all files in directory.
do
      echo "$filename" | grep -q " "         #  Check whether filename
      if [ $? -eq $FOUND ]                   #+ contains space(s).
      then
        fname=$filename                      # Yes, this filename needs 
work.
        n=`echo $fname | sed -e "s/ /_/g"`   # Substitute underscore for 
blank.
        mv "$fname" "$n"                     # Do the actual renaming.
        let "number += 1"
      fi
done

if [ "${number}" -eq "$ONE" ]                 # For correct grammar.
then
     echo "${number} file renamed."
else
     echo "${number} files renamed."
fi

exit 0

I didn't write it and don't know who did but I hope it helps somebody 
somewhere sometime.

-- 
A riddle, wrapped in a mystery, inside an enigma but that's my story and I'm 
stickin' to it.


------------------------------------------------------------------------------
Get 100% visibility into Java/.NET code with AppDynamics Lite!
It's a free troubleshooting tool designed for production.
Get down to code-level detail for bottlenecks, with <2% overhead. 
Download for free and get started troubleshooting in minutes. 
http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk
_______________________________________________
DSpace-tech mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/dspace-tech
List Etiquette: https://wiki.duraspace.org/display/DSPACE/Mailing+List+Etiquette

Reply via email to