osx - Remove spaces from filenames in folder -
i have situation need daily go on 400+ files in folder on xsan , replace spaces under-scores in filenames of files.
does 1 have script @ hand can run via terminal example me?
here go, loops through files (and folders) in current directory:
for oldname in * newname=`echo $oldname | sed -e 's/ /_/g'` mv "$oldname" "$newname" done
please note overwrite files same name. is, if there 2 files have otherwise identical filenames, 1 has underscore(s) other has space(s). in situation, 1 had underscores overwritten 1 had spaces. longer version skip cases instead:
for oldname in * newname=`echo $oldname | sed -e 's/ /_/g'` if [ "$newname" = "$oldname" ] continue fi if [ -e "$newname" ] echo skipping "$oldname", because "$newname" exists else mv "$oldname" "$newname" fi done
Comments
Post a Comment