It is simple. I cannot stand when people use spaces when naming files. It sometimes wrecks console commands and makes the output of ls ugly.
The challenge is to write a program (only ascii characters) which
- renames all files (including directories) in the current directory to versions with spaces removed or replaced by '_'
- on collision, you need to append a unique identifier (up to you)
- descends recursively into all subdirectories
You can assume UNIX-style path names. Who would need this program on a Windows machine anyways?
This is code golf, the shortest program wins (#ascii characters). Since I hate spaces so much, each space has to be counted twice.
Please provide your language, score, program and a short description of how to run it.
The program must compile and execute with reasonable effort on my linux machine.
EDIT: As Etan requested a file structure for testing, here is the script I currently use to create a suitable file tree:
#!/bin/bash
rm -r TestDir
touchfiles()
{
touch my_file
touch my__file
touch "my file"
touch "my file"
touch " my_file "
}
mkdir TestDir
cd TestDir
touchfiles
for dir in "Test Sub" Test_Sub "Te stSub" Te_stSub
do
mkdir "$dir"
cd "$dir"
touchfiles
cd ..
done