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

...

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

···

On Feb 13, 6:16 am, "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de> wrote:

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

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

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

# 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

···

On Wed, 14 Feb 2007, Rebhan, Gilbert 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 ?

--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama
cat a.rb

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 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 ?

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

make sure it's finding them:

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

is it?

-a

···

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

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

--
we can deny everything, except that we have the possibility of being better.
simply reflect on that.
- the dalai lama

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

...

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

···

On Feb 14, 2:51 am, "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de> wrote:

Hi,

···

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

...

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.

···

On Feb 14, 11:10 am, "Rebhan, Gilbert" <Gilbert.Reb...@huk-coburg.de> wrote: