From: "Mariusz Pękala" Date: 2007-06-14T22:13:48+09:00 Subject: Re: Dir copy with rename --L6iaP+gRLNZHKoI4 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2007-06-14 21:53:17 +0900 (Thu, Jun), Rebhan, Gilbert wrote: > =20 > Hi, >=20 > -----Original Message----- > From: Mariusz Pekala [mailto:skoot@ideico.net]=20 > Sent: Thursday, June 14, 2007 2:35 PM > To: ruby-talk ML > Subject: Re: Dir copy with rename >=20 > /* > The standard procedure with 'find' utility, when performing recursive > delete or similiar operations is to use '-depth' option, so it first > processes the files inside, and then directories. > */ >=20 > OK i'll have a look >=20 > I have =3D >=20 > require 'fileutils' >=20 > srcdir=3D"Y:/test" > destdir=3D"Y:/test_" >=20 > Dir.mkdir(destdir) unless File.exists?(destdir) >=20 > Dir.entries(srcdir).each do | i |=20 > if i !=3D'.' && i !=3D'..' && i !=3D~ /\./ > FileUtils.cp_r Dir["#{srcdir}/**"], destdir,:verbose =3D> true > end > end >=20 >=20 > my problem =3D > i don't know how to put the rename part in, > and how to do it without fileutils, because i have to do it > with jruby, and jruby doesn't have fileutils >=20 > "No such file to load -- fileutils" >=20 > Regards, Gilbert In fact you may choose two ways: 1) copy the structure 2) rename just the files inside If you choose 1), then you should process the top items first (the opposite I have suggested), and if you choose 2) then you should process the deepest items first. I don't recall any already-ready object which will do it for you, but you c= an write your own recursive directory parser, walk thru the directory structure and = rename (File.rename) each file which matches your pattern. Just remember to call the recursive function on found direcotry before you rename it, and everything should be OK. Just use Dir['*'] not Dir['**/**'] --=20 Ceterum censeo Internet Explorer esse delendam. --L6iaP+gRLNZHKoI4 Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7-ecc0.1.6 (GNU/Linux) iD8DBQFGcT8csnU0scoWZKARAjPQAKDWIl2sUGSqUxiYIBGZY6XKQel/cQCbBSnA SNy7W62jQM8JCRoD7212T9M= =MJgZ -----END PGP SIGNATURE----- --L6iaP+gRLNZHKoI4--