Problem with File.mv

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

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

Hi,

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

OK, after a test on a local drive =

seems to be a problem with LAN path

Y:/ is \LAN\HOME…

how to get around that ??

  1. 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

On Wed, 14 Feb 2007, Rebhan, Gilbert wrote:

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

Hi,

On Feb 13, 10:19 am, “Rebhan, Gilbert” [email protected]
wrote:

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

On Wed, 14 Feb 2007, Rebhan, Gilbert wrote:

require “fileutils”
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

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

Hi,

Hi,

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.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs