From: "Mariusz Pękala" Date: 2007-06-14T18:26:24+09:00 Subject: Re: Dir copy with rename --9amGYk9869ThD9tj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2007-06-14 16:01:30 +0900 (Thu, Jun), Rebhan, Gilbert wrote: >=20 > Hi, >=20 > i want to copy a dir recursive with all files included,=20 > but rename all dirnames that match a pattern, i.e. >=20 > /srcdir > /bla/foobar/blabla > /bla/test/subtest/foobar > /foobar/test > /foobar >=20 > should be=20 >=20 > /targetdir > /bla/foobaz/blabla > /bla/test/subtest/foobaz > /foobaz/test > /foobaz >=20 > i tried =3D >=20 > re=3D/foobar/ > sub=3D"foobaz" >=20 > Dir['Y:/test/**/**'].each { |old| > next if old =3D=3D '.'||old=3D=3D '..'||old =3D~ /\./ > unless /re/.match(old) > new =3D old.sub(re,sub) > File.rename(old,new) > end > } >=20 > the /foobar folder on first level and on second level get renamed, but > it dosn't > work, when i have /foobar on the third level, means >=20 > /foobar/foobar/foobar gets=20 > /foobaz/foobaz/foobar and Exit Code 1 >=20 > /test/sub3/foobar/foobar gets > /test/sub3/foobaz/foobar and Exit Code 1 >=20 > Error message i.e. =3D > No such file or directory - Y:/test/sub3/foobar/foobar or > Y:/test/sub3/foobaz/foobar >=20 > Any ideas what's wrong ? Are you sure the code you posted here is the code you really run? I guess you want 'if' instead of 'unless', because you want to rename the file if the re matches, not if it does not. Second - you should use re.match(old) not /re/.match(old) since 're' variable is already a Regexp. Having these errors I doubt you would have any file renamed. --=20 Ceterum censeo Internet Explorer esse delendam. --9amGYk9869ThD9tj Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7-ecc0.1.6 (GNU/Linux) iD8DBQFGcQnMsnU0scoWZKARAkxJAJ9b20ILBTlCv6LtK5GpxAVoLY8zFwCgm94Z 6RmwQYN8Y4jM+C3wVBO4LTc= =Lapl -----END PGP SIGNATURE----- --9amGYk9869ThD9tj--