The question is related to the answer about renaming files recursively.
The code, changed to replace dashes, does not work with cases such as:
./Beginners Tools/Hello's -Trojans-/bif43243
./Linux/Nux Col - 1 Works (TEX & Pdf) - T'eouhsoe & More (33323 - 34432)
./Git/peepcode-git-mov/c6_branch_merge.mov
./haskell/OS 2007 - T aoue
./B Sites for Get-Big
It worked with cases such as:
./oeu'oeu - X ee ls - Feb 2008.pdf
So I need to parse the data. How can I correctly replace dashes?
[Details]
The code is from the link, but changed to replace "-":
import os
for dirpath, dirs, files in os.walk(your_path):
for filename in files:
if '&' in filename:
os.rename(
os.path.join(dirpath, filename),
os.path.join(dirpath, filename.replace('-', '_'))
)
The Python did not replace every dash. I think it is because the names contains special signs that stopped the script earlier. So I encountered errors in archieving:
tar cvzf sed_backup.tar.gz `find documents | sed s/\.*/\'\&\'/`
tar: rojans-: Cannot stat: No such file or directory
tar: Error is not recoverable: exiting now
Because of the signs " ' " and " - " still left in the names, the tar-command interpret " ' " as an end for the find-command and " - " as an option sign in the path "./Beginners Tools/Hello's -Trojans-/bif43243"