On mac OS X, how to get a bash script working to change over a 1,000 files and sub-directories and many sub-sub-directories in the current working directory.
Tried using a script from Find and replace filename recursively in a directory answer, however that doesn't take into account filenames or directories that have leading or trailing spaces, as the spaces need to be escaped. However as you can see the below line the path is also escaped and the script doesn't work.
find . -name '* ' -type d -exec bash -c 'echo mv "$1"/ \""${1/ /}\""' -- {} \;
(Note: Yes I'm using echo to see the commands.)
The bash script needs to trim leading and trailing spaces of both files and directories. By "trim" I mean remove leading and trailing spaces and leaving the spaces in between words alone.
Example Structure:
./
./ Leading Space/
./ Leading Space/ Text File With Leading Space.txt
./Trailing Space /
./Trailing Space / Multiple Trailing and Leading Spaces /
./Trailing Space / Multiple Trailing and Leading Spaces / Trailing and Leading Spaces Text File .txt
Note: The answer will need to work on any default mac OS X. I will not accept an answer that uses third party applications or plugins, including Mac Automator and perl rename
.