F. Senault
4/2/2009 7:27:00 PM
Le Thu, 2 Apr 2009 13:22:01 -0500, Emmek on Rails a écrit :
> Sorry, what do You exactly mean? I want to copy just images from
> original location. I'm trying to do something with
>
> cp_r "public/uploaded/users/#{u.login[0..0]}/#{u.login}/logo/."
>
> but I don't know what to put at the end of this path to copy just jpgs,
> gifs and pngs.
It won't work that way ; cp_r copies the whole directories. You need to
use Dir.glob or Find.find to select the files and then copy them one by
one.
Again, pretty much untested :
Dir.chdir("/public/uploaded/users/#{u.login[0..0]}/#{u.login}/logo") do
Dir.glob("**/*.{jpg,png,gif}").each do |f|
f2 = "/public/uploaded/logos/#{u.id}/#{f}"
mkdir_p File.dirname(f2)
cp_r f, f2
end
end
(You'll need at least to specify absolute paths if public isn't in the
root.)
Fred