You could probably use the ‘find’ command. I need to check exact syntax. The command can execute another command on all found files matching a criteria. Something kinda like this
mkdir test
cd test
echo "a" > a.html
ls
> a.html
mv a.html b.html
ls
> b.html
-exec is a parameter passed to the find program in the form of -exec command ;
As you might imagine, it executes the specified command on each matched file.
You can read more here: http://www.computerhope.com/unix/ufind.htm (do an in page search for “exec”).
This assumes you are in the photos directory (the root of your webapp).
If you just use exec, it’ll create one single file in your root dir named “Photo.php”, whereas execdir preserves the context.
I’m not sure how that works on a Mac.
Try it out and let us know how you get on.
A -exec command must be terminated with a ; (so you usually need to type ; or ‘;’ to avoid interpretion by the shell)
IMPORTANT
Please make a backup of your web app before running any commands such as find on it.
If you get it wrong, it is quite possible to delete stuff.
a total of 11 sections, with an average of about six pages per section, for a total of approx 80 photos.jsp files I need to rename to photos.php… all of them in
Create a new file on your computer.
Name it “rename_photos.rb” or something similar.
Copy the following into the newly created file:
def rename_file(old_path)
new_path = old_path.sub("photos.jsp", "photos.php")
puts "Old path: #{old_path}"
puts "New path: #{new_path}"
puts
#File.rename(old_path, new_path)
end
def build_tree(start_path)
Dir.open(start_path).entries.each do |file_name|
full_path = File.join(start_path, file_name)
next if /^\./ =~ file_name
if File.directory?(full_path)
build_tree(full_path)
elsif (file_name == "photos.jsp")
rename_file(full_path)
end
end
end
build_tree("/photos")
Ensure the start path is pointing to the root of your app.
Then run the file with ruby rename_photos.rb
Check that the output is correct.
If so, un-comment this line: #File.rename(old_path, new_path) (by removing the #).
Run again.
And that should hopefully work.
Let us know how you get on.
thank you very much for your help… I appreciate you taking the time…
this is what I get when I run the .rb file:
$ ruby rename_photos.rb
rename_photos.rb:10:in `open': No such file or directory - /photos (Errno::ENOENT)
from rename_photos.rb:10:in `build_tree'
from rename_photos.rb:21
question is: where does this file rename_photos.rb have to be? I put it at root of webapp (/photos/)
“start path”… you mean in the terminal I need to be at that location, right? yes that’s where I am, and where rename_photos.rb is…
(I added a trialing ‘/’ at the end of ‘/photos’ on last line of rename_photos.rb, get exact same thing…)