[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Unix-ify File Names



Masatran, R. Deepak wrote:
> Since I frequently receive files from Microsoft Windows users, is there any
> utility to unix-ify file names, that is, use lower case exclusively, use
> hyphen as separator, etc.?
> 

I wrote this little zsh script once; it unixifies all file names in the
current and sub directories. This may or may not work in other shells (I
believe bash is quite feature-rich as well, but I don't use it)



#!/bin/zsh

FS="
"

for f in **/*
do
  #required for files in the current dir.
  f=./$f
  #dir of file
  fp1=${f%/*}/
  #name of file
  fp2=${f##*/}
  #dir should already be anti-spaced and lower-cased
  f=$fp1:gs/\ /_/:l$fp2
  #the new name; anti-spaced and lower-cased
  f2=$f:gs/\ /_/:l

  if ! [[ $f = $f2 ]]
  then
    mv -v "$f" "$f2"
  fi
done


Attachment: signature.asc
Description: OpenPGP digital signature


Reply to: