[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Problem with File.mv

Rebhan, Gilbert

2/13/2007 11:16:00 AM


Hi,

running Ruby 1.8.4 under Windows 2000

i have a dir with subdirs =

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

i look for the eldest dir with =

CANDIDATE = Dir["#{SRCDIR}/*"].collect { |f|
[test(?M, f), f]
}.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 =

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)

i tried with =

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

no error, but no move, nothing happens


What's wrong ?!


Regards, Gilbert



20 Answers

Chris Hulan

2/13/2007 2:30:00 PM

0

On Feb 13, 6:16 am, "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
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

Rebhan, Gilbert

2/13/2007 2:57:00 PM

0


Hi,

-----Original Message-----
From: ChrisH [mailto:chris.hulan@gmail.com]
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 '
where '.' and '..' are skipped =

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 = src + "/" + e
newname = fullname.sub(Regexp.new(Regexp.escape(src)),dst)
if FileTest::directory?(fullname)
recurse(fullname,newname)
FileUtils.cp(fullname, newname, :verbose => true)
else
puts "??? : #{fullname}"
end
end
end


and

CANDIDATE = Dir["#{SRCDIR}/*"].collect { |f|
[test(?M, f), f]
}.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':
Permission denied - T:/rubytest/deploy/E023889/INCLIB (Errno::EACCES)

??!

Regards, Gilbert


Rebhan, Gilbert

2/13/2007 3:06:00 PM

0


Hi,

sorry forgot, if i use def recurse with =

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

i get =

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

if i use

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

i get =

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


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

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

??

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

Regards, Gilbert

-----Original Message-----
From: Rebhan, Gilbert [mailto:Gilbert.Rebhan@huk-coburg.de]
Sent: Tuesday, February 13, 2007 3:57 PM
To: ruby-talk ML
Subject: Re: Problem with File.mv


Hi,

-----Original Message-----
From: ChrisH [mailto:chris.hulan@gmail.com]
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 '
where '.' and '..' are skipped =

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 = src + "/" + e
newname = fullname.sub(Regexp.new(Regexp.escape(src)),dst)
if FileTest::directory?(fullname)
recurse(fullname,newname)
FileUtils.cp(fullname, newname, :verbose => true)
else
puts "??? : #{fullname}"
end
end
end


and

CANDIDATE = Dir["#{SRCDIR}/*"].collect { |f|
[test(?M, f), f]
}.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':
Permission denied - T:/rubytest/deploy/E023889/INCLIB (Errno::EACCES)

??!

Regards, Gilbert



Rebhan, Gilbert

2/13/2007 3:19:00 PM

0


OK, after a test on a local drive =

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 = src + "/" + e
newname = fullname.sub(Regexp.new(Regexp.escape(src)),dst)
if FileTest::directory?(fullname)
recurse(fullname,newname)
FileUtils.cp(fullname, newname, :verbose => true)
else
puts "??? : #{fullname}"
end
end
end

works now, but not as i need it to =


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 ?



Regards, Gilbert





Ara.T.Howard

2/13/2007 3:57:00 PM

0

Chris Hulan

2/13/2007 4:09:00 PM

0

On Feb 13, 10:19 am, "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
wrote:
> ...
> 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

Rebhan, Gilbert

2/14/2007 7:14:00 AM

0


Hi,

-----Original Message-----
From: ara.t.howard@noaa.gov [mailto:ara.t.howard@noaa.gov]
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

Regards, Gilbert





Ara.T.Howard

2/14/2007 7:24:00 AM

0

Rebhan, Gilbert

2/14/2007 7:51:00 AM

0


Hi,

-----Original Message-----
From: ara.t.howard@noaa.gov [mailto:ara.t.howard@noaa.gov]
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 => dst; fu.mv e, dst}

is it?
*/

yup, sorry i think i had a wrong path.

But what's really strange =

if i use =

1. require "fileutils"

src = "C:/test_deploy/E023889/INCLIB"
dst = "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 =

2. require "fileutils"

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


i get the error :

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

3.

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

i get the error :

{"C:/test_deploy/E023889/INCLIB"=>"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 =

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/*
to C:/HOST/INCLIB/* and so on

Any other ways as with FileUtils ?


Regards, GIlbert




Chris Hulan

2/14/2007 3:49:00 PM

0

On Feb 14, 2:51 am, "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de>
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