I need to rename approximately 10,000 folders located on a Linux server. All I need to do is replace the space in the folder name (as in Big House) with an underscore (turning it into Big_House for example). How can I automate this process?
I guess shell scripting (or through perl) can make it easy for you. I hope some linux guru would come to your rescue in this thread soon.
Pop the below code in a php script and chmod it so it can execute (chmod +x). Please test it out in a controlled environment first, I didn't really do any real world testing on it. You might want to add set_time_limit() if the script is timing out because of so many folders. #!/usr/bin/php -q <?php $count = 0; if (($dh = opendir("./"))) { while (($file = readdir($dh)) !== false) { if ($file == "." || $file == "..") continue; if (!is_dir($file)) continue; $new_filename = str_replace(" ", "_", $file); rename($file, $new_filename); $count++; echo "Renaming $file -> $new_filename \n"; } echo "Renamed: $count files \n"; } ?> PHP:
Thank you very much! The script worked perfectly - all the folders were correctly renamed in about 5 mins or so! That script was a huge timesaver - thanks again
I have a similar problem. Is there any solution that would replace the references of those folders and files in the HTML files?