Problem with File.mv

R

Rebhan, Gilbert

Hi,

running Ruby 1.8.4 under Windows 2000

i have a dir with subdirs =3D

deploy_tmp/
/subdir1
/subsubdir1
/subsubdir2
/subdir2
/subsubdir1
/subsubdir2
...

i look for the eldest dir with =3D

CANDIDATE =3D Dir["#{SRCDIR}/*"].collect { |f|=20
[test(?M, f), f]=20
}.sort.collect { |f| f[1] }[0]


and then i want to move all dirs + files beyond
the CANDIDATE folder which is all under subdir1
in the structure above, i tried with =3D

Dir.foreach({CANDIDATE) { |x|=20
FileUtils.mv x, 'Y:/bla/'<<x}

but that gave me an error =3D

c:/ruby/lib/ruby/1.8/fileutils.rb:495:in `mv': File exists - Y:/bla/.
(Errno::EEXIST)

i tried with =3D

Dir.foreach("#{CANDIDATE}") { |x| FileUtils.mv x, 'Y:/bla/'<<x, :force
=3D> true}

no error, but no move, nothing happens


What's wrong ?!


Regards, Gilbert
 
C

ChrisH

On Feb 13, 6:16 am, "Rebhan, Gilbert" <[email protected]>
wrote:
....
Dir.foreach({CANDIDATE) { |x|
FileUtils.mv x, 'Y:/bla/'<<x}

but that gave me an error =

c:/ruby/lib/ruby/1.8/fileutils.rb:495:in `mv': File exists - Y:/bla/.
(Errno::EEXIST) ....
What's wrong ?!

Regards, Gilbert

Looks like you need to ensure you are not trying to move the '.' (and
also '..') dirs.

cheers
 
R

Rebhan, Gilbert

=20
Hi,

-----Original Message-----
From: ChrisH [mailto:[email protected]]=20
Sent: Tuesday, February 13, 2007 3:30 PM
To: ruby-talk ML
Subject: Re: Problem with File.mv

/*
Looks like you need to ensure you are not trying to move the '.' (and
also '..') dirs.
*/

hm, i tried with a method found in 'The Ruby Way '=20
where '.' and '..' are skipped =3D

def recurse(src, dst)
#Dir.mkdir(dst)
# commented out as dstdir already exists
Dir.foreach(src) do |e|
# Don't bother with . and ..
next if [".",".."].include? e
fullname =3D src + "/" + e
newname =3D fullname.sub(Regexp.new(Regexp.escape(src)),dst)
if FileTest::directory?(fullname)
recurse(fullname,newname)
FileUtils.cp(fullname, newname, :verbose =3D> true)
else
puts "??? : #{fullname}"
end
end
end


and

CANDIDATE =3D Dir["#{SRCDIR}/*"].collect { |f|=20
[test(?M, f), f]=20
}.sort.collect { |f| f[1] }[0]

recurse("#{CANDIDATE}", "T:/Foobar")

gave me another error :

c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `initialize':=20
Permission denied - T:/rubytest/deploy/E023889/INCLIB (Errno::EACCES)

??!

Regards, Gilbert
 
R

Rebhan, Gilbert

Hi,

sorry forgot, if i use def recurse with =3D

FileUtils.cp(fullname, newname, :verbose =3D> true)

i get =3D

c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `initialize':=20
Permission denied - T:/rubytest/deploy/E023889/INCLIB (Errno::EACCES)

if i use=20

FileUtils.mv(fullname, newname, :verbose =3D> true)
when targetdir is already existent

i get =3D

c:/ruby/lib/ruby/1.8/fileutils.rb:495:in `mv': File exists -
T:/Foobar/INCLIB (Errno::EEXIST)


if i use=20
Dir.mkdir(dst)
...
FileUtils.mv(fullname, newname, :verbose =3D> true)=20
and the targetdir is not existent before the message call i get =3D

c:/ruby/lib/ruby/1.8/fileutils.rb:501:in `rename':=20
Permission denied - T:/rubytest/deploy/E023889/INCLIB or
Y:/Foobar/INCLIB (Errno::EACCES)

??

Env =3D Windows 2000, Ruby 1.8.4 (2006-04-14) [i386-mswin32]

Regards, Gilbert

-----Original Message-----
From: Rebhan, Gilbert [mailto:[email protected]]=20
Sent: Tuesday, February 13, 2007 3:57 PM
To: ruby-talk ML
Subject: Re: Problem with File.mv

=20
Hi,

-----Original Message-----
From: ChrisH [mailto:[email protected]]=20
Sent: Tuesday, February 13, 2007 3:30 PM
To: ruby-talk ML
Subject: Re: Problem with File.mv

/*
Looks like you need to ensure you are not trying to move the '.' (and
also '..') dirs.
*/

hm, i tried with a method found in 'The Ruby Way '=20
where '.' and '..' are skipped =3D

def recurse(src, dst)
#Dir.mkdir(dst)
# commented out as dstdir already exists
Dir.foreach(src) do |e|
# Don't bother with . and ..
next if [".",".."].include? e
fullname =3D src + "/" + e
newname =3D fullname.sub(Regexp.new(Regexp.escape(src)),dst)
if FileTest::directory?(fullname)
recurse(fullname,newname)
FileUtils.cp(fullname, newname, :verbose =3D> true)
else
puts "??? : #{fullname}"
end
end
end


and

CANDIDATE =3D Dir["#{SRCDIR}/*"].collect { |f|=20
[test(?M, f), f]=20
}.sort.collect { |f| f[1] }[0]

recurse("#{CANDIDATE}", "T:/Foobar")

gave me another error :

c:/ruby/lib/ruby/1.8/fileutils.rb:1245:in `initialize':=20
Permission denied - T:/rubytest/deploy/E023889/INCLIB (Errno::EACCES)

??!

Regards, Gilbert
 
R

Rebhan, Gilbert

OK, after a test on a local drive =3D

1.
seems to be a problem with LAN path

Y:/ is \\LAN\HOME\....

how to get around that ??

2. the method

def recurse(src, dst)
#Dir.mkdir(dst)
# commented out as dstdir already exists
Dir.foreach(src) do |e|
# Don't bother with . and ..
next if [".",".."].include? e
fullname =3D src + "/" + e
newname =3D fullname.sub(Regexp.new(Regexp.escape(src)),dst)
if FileTest::directory?(fullname)
recurse(fullname,newname)
FileUtils.cp(fullname, newname, :verbose =3D> true)
else
puts "??? : #{fullname}"
end
end
end

works now, but not as i need it to =3D


i want all files from=20
T:/rubytest/deploy/E023889/INCLIB

move to the folder
T:/Foobar/INCLIB

but with the method above i get =3D

T:/Foobar/INCLIB/INCLIB

how to change that ?



Regards, Gilbert



=20
 
A

ara.t.howard

i want all files from
T:/rubytest/deploy/E023889/INCLIB

move to the folder
T:/Foobar/INCLIB

but with the method above i get =

T:/Foobar/INCLIB/INCLIB

how to change that ?

# untested - should work though...


require "fileutils"

src = "T:/rubytest/deploy/E023889/INCLIB"
dst = "T:/Foobar/INCLIB"

fu = FileUtils
f = File
d = Dir

fu.mkdir_p dst

d.glob(f.join(src,'*'){|e| fu.mv e, dst}


regards

-a
 
C

ChrisH

...
i want all files from
T:/rubytest/deploy/E023889/INCLIB

move to the folder
T:/Foobar/INCLIB

but with the method above i get =

T:/Foobar/INCLIB/INCLIB

how to change that ?
Just give the parent dir as the destination, in your case 'T:/Foobar'

I am trying to reproduce but also getting errors. seems like
directories are
not being recognized as such? Seem to recall some issues with file
handling on windows,
will check into it if I have time.

Cheers
 
R

Rebhan, Gilbert

=20
Hi,

-----Original Message-----
From: (e-mail address removed) [mailto:[email protected]]=20
Sent: Tuesday, February 13, 2007 4:57 PM
To: ruby-talk ML
Subject: Re: Problem with File.mv

*/
# untested - should work though...


require "fileutils"

src =3D "T:/rubytest/deploy/E023889/INCLIB"
dst =3D "T:/Foobar/INCLIB"

fu =3D FileUtils
f =3D File
d =3D Dir

fu.mkdir_p dst

d.glob(f.join(src,'*'){|e| fu.mv e, dst}
*/

after changing the line d.glob ... into

d.glob(f.join(src,'*')){|e| fu.mv e, dst}

it run's with Exit Code 0 put only the fu.mkdir does his work,
means dst is created but nothing more, no files under T:/Foobar/INCLIB

Regards, Gilbert
 
A

ara.t.howard

-----Original Message-----
From: (e-mail address removed) [mailto:[email protected]]
Sent: Tuesday, February 13, 2007 4:57 PM
To: ruby-talk ML
Subject: Re: Problem with File.mv

*/
# untested - should work though...


require "fileutils"

src = "T:/rubytest/deploy/E023889/INCLIB"
dst = "T:/Foobar/INCLIB"

fu = FileUtils
f = File
d = Dir

fu.mkdir_p dst

d.glob(f.join(src,'*'){|e| fu.mv e, dst}
*/

after changing the line d.glob ... into

d.glob(f.join(src,'*')){|e| fu.mv e, dst}

it run's with Exit Code 0 put only the fu.mkdir does his work,
means dst is created but nothing more, no files under T:/Foobar/INCLIB

make sure it's finding them:

d.glob(f.join(src,'*')){|e| p e => dst; fu.mv e, dst}

is it?

-a
 
R

Rebhan, Gilbert

=20
Hi,

-----Original Message-----
From: (e-mail address removed) [mailto:[email protected]]=20
Sent: Wednesday, February 14, 2007 8:24 AM
To: ruby-talk ML
Subject: Re: Problem with File.mv

/*
make sure it's finding them:

d.glob(f.join(src,'*')){|e| p e =3D> dst; fu.mv e, dst}

is it?
*/

yup, sorry i think i had a wrong path.

But what's really strange =3D

if i use =3D

1. require "fileutils"

src =3D "C:/test_deploy/E023889/INCLIB"
dst =3D "Y:/HOST" # where Y: is a mapped LAN drive

it run's with Exit Code 0 and puts all files under src/INCLIB
into dst root folder

but if i use =3D

2. require "fileutils"

src =3D "C:/test_deploy/E023889"
dst =3D "Y:/HOST" # where Y: is a mapped LAN drive


i get the error :

{"C:/test_deploy/E023889/INCLIB"=3D>"Y:/HOST"}
c:/ruby/lib/ruby/1.8/fileutils.rb:501:in `rename':=20
Permission denied - C:/host_deploy/E023889/INCLIB or Y:/HOST/INCLIB
(Errno::EACCES)

3.=20

src =3D "C:/test_deploy/E023889"
dst =3D "C:/HOST" # where C: is a local drive

i get the error :

{"C:/test_deploy/E023889/INCLIB"=3D>"C:/HOST"}
c:/ruby/lib/ruby/1.8/fileutils.rb:495:in `mv': File exists - C:/HOST
(Errno::EEXIST)

the dst dir is already existent in 1.,2.,3.


Seems like the FileUtils on Windows are really buggy ?!?

Any workaround for that ? Here is what i want to achieve =3D

i have a deployroot, named test_deploy, there are 1 - n E...folders in
it
with stuff that should get checked in to cvs. so i need

C:/test_deploy/E023889/*.* copied over to an existing folder C:/HOST,
which is a cvs workspace, so it's copy C:/test_deploy/E023889/INCLIB/*=20
to C:/HOST/INCLIB/* and so on

Any other ways as with FileUtils ?


Regards, GIlbert
 
C

ChrisH

On Feb 14, 2:51 am, "Rebhan, Gilbert" <[email protected]>
wrote:
....
C:/test_deploy/E023889/*.* copied over to an existing folder C:/HOST,
which is a cvs workspace, so it's copy C:/test_deploy/E023889/INCLIB/*
to C:/HOST/INCLIB/* and so on

Any other ways as with FileUtils ?

If you want to copy, than look at FileUtils.cp_r, it will recursively
copy a directory, creating the directory structure as needed

Cheers
 
R

Rebhan, Gilbert

=20
Hi,
-----Original Message-----
From: ChrisH [mailto:[email protected]]=20
Sent: Wednesday, February 14, 2007 4:50 PM
To: ruby-talk ML
Subject: Re: Problem with File.mv

/*
If you want to copy, than look at FileUtils.cp_r, it will recursively
copy a directory, creating the directory structure as needed
*/

If i do FileUtils.cp_r("C:/test1/**", "C:/test2",:verbose =3D> true)

i get C:/test2
/test1


but i want all in C:/test1 copy over to C:/test2 but without
the roodir /test1 itself

How to cp_r but without the root of src ?

Regards, Gilbert
 
C

ChrisH

On Feb 14, 11:10 am, "Rebhan, Gilbert" <[email protected]>
wrote:
....
but i want all in C:/test1 copy over to C:/test2 but without
the roodir /test1 itself

How to cp_r but without the root of src ?
From the docs on File.cp_r:
# If you want to copy all contents of a directory instead of the
# directory itself, c.f. src/x -> dest/x, src/y -> dest/y,
# use following code.
FileUtils.cp_r 'src/.', 'dest' # cp_r('src', 'dest') makes src/
dest,
# but this doesn't.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,731
Latest member
MarcyGipso

Latest Threads

Top