foreigndude

Member
Aug 16, 2005
12
0
151
Hi all,

Don't know where to go with this, but I could not find anything on this subject on this forum.

I'm a WHM/Cpanel user and one of my sites is running on php-Nuke. I noticed that my security configuration blocks all users that click on a file whose filename contains parenthesis [e.g., Artist Name - My first song (2005-2006).mp3].

So, what I'm trying to do is mass rename all the files that have "(" and/or ")" in their filename. Basically, I need a way to replace "(" and ")" with a space or "-" or anything else, to prevent the security system from blocking the users.

Thoughts?

I know this can be done through shell somehow, but I'm not sure how to do it. Any help will be greatly appreciated!
 

nxds

Well-Known Member
Jan 6, 2006
53
0
156
Here's one way of doing it. This renames files from the current directory down (not dirs) with ('s or )'s replacing ( with { and ) with }. Change the tr command if you want to have different characters substituted (e.g. tr -- '()' '--' to replace with -'s).

PHP:
find . -type f -a -regex '.*[()][()]*[^/]*' | while read name; do base=$(basename "$name"); dir=$(dirname "$name"); newbase=$(echo "$base" | tr -- '()' '{}'); echo mv "$name" "$dir/$newbase"; done
Remove the echo before mv to actually rename files.