Permission denied - (Errno::EACCES)- Help!

Hi i remember posting this before but I needed to raise the issue again
because i dont think is due to my user acess rights.
My part of my code looks like this:
Dir.glob(src) do |file|
regexp = Regexp.new($exception)
puts match = regexp.match(File.basename(file))
if match == nil
if $createDestDir == true
begin
Dir.chdir($destination)
Dir.mkdir(d)
FileUtils.move file, dst #:force => true
rescue Errno::EEXIST
FileUtils.move file, dst #:force => true
end #rescue

and when running the script this error occurs:

c:/ruby/lib/ruby/1.8/fileutils.rb:505:in `rename’: Permission denied -
C:/MOVTEST/TESTING/NEW/
03-09/20080402 (Errno::EACCES)

However when i tried moving files, it could execute the mv command
successfully. Therefore, I think it’s not due to my user access rights
as I am an admin on my PC. On the other hand, I’m not using the files or
folders while i was running the script. Can anyone please help me with
this error? Thanks!

Clement Ow wrote:

Hi i remember posting this before but I needed to raise the issue again
because i dont think is due to my user acess rights.
My part of my code looks like this:
Dir.glob(src) do |file|
regexp = Regexp.new($exception)
puts match = regexp.match(File.basename(file))
if match == nil
if $createDestDir == true
begin
Dir.chdir($destination)
Dir.mkdir(d)
FileUtils.move file, dst :force => true
rescue Errno::EEXIST
FileUtils.move file, dst :force => true
I cant use force => true because it handles the error but still does not
move the files.
end #rescue

and when running the script this error occurs:

c:/ruby/lib/ruby/1.8/fileutils.rb:505:in `rename’: Permission denied -
C:/MOVTEST/TESTING/NEW/
03-09/20080402 (Errno::EACCES)

However when i tried moving files, it could execute the mv command
successfully. Therefore, I think it’s not due to my user access rights
as I am an admin on my PC. On the other hand, I’m not using the files or
folders while i was running the script. Can anyone please help me with
this error? Thanks!

I found out that Im able to move files, like my excel files to my dest
folder successully… But I cant move a folder that contains the same
excel file and it’ll give the same error as the above (i.e Errno:EACCES.
Could there be a possibility that there’s a bug in the fileutils module?

double check the directory exists ?

On Thu, Apr 24, 2008 at 10:23 PM, Clement Ow

Roger P. wrote:

double check the directory exists ?

On Thu, Apr 24, 2008 at 10:23 PM, Clement Ow

The directory exists actually. When I try to move it manually myself it
is able to work, so i suppose it’s some bug in the fileutils module.
I had no choice but to copy the files to the dest then delete the files
in the source. =/
I don’t know if anyone can explain what is wrong with the fileutils
module?

From: Clement Ow [mailto:[email protected]]

> On Thu, Apr 24, 2008 at 10:23 PM, Clement Ow

The directory exists actually. When I try to move it manually

myself it

is able to work, so i suppose it’s some bug in the fileutils module.

I had no choice but to copy the files to the dest then delete

the files

in the source. =/

I don’t know if anyone can explain what is wrong with the fileutils

module?

i cannot reproduce the behaviour on my windows pc.

can you post a more vivid session?

eg,

first we create a dummy source file

FileUtils.touch “\test\test1\test2\testfile.txt”
#=> ["\test\test1\test2\testfile.txt"]

let’s see if it was created

i think yes…

system " dir \test\test1\test2\testfile.txt"
Volume in drive C is hd
Volume Serial Number is 7CD8-B514

Directory of C:\test\test1\test2

04/29/2008 09:59 AM 0 testfile.txt
1 File(s) 0 bytes
0 Dir(s) 1,172,480,000 bytes free
#=> true

now, let’s examine our destination folder

there’s should be no files there yet…

system “dir .\test”
Volume in drive C is hd
Volume Serial Number is 7CD8-B514

Directory of C:\family\ruby\test

04/29/2008 09:58 AM .
04/29/2008 09:58 AM …
0 File(s) 0 bytes
2 Dir(s) 1,172,480,000 bytes free
#=> true

NOW, LET’S DO THE MV

FileUtils.mv “\test\test1\test2\testfile.txt”, “.\test”
#=> 0

REEXAMINE THE DESTINATION FOLDER IF IT CONTAINS THE FILE

YES IT DOES!

system “dir .\test”
Volume in drive C is hd
Volume Serial Number is 7CD8-B514

Directory of C:\family\ruby\test

04/29/2008 10:00 AM .
04/29/2008 10:00 AM …
04/29/2008 09:59 AM 0 testfile.txt
1 File(s) 0 bytes
2 Dir(s) 1,172,480,000 bytes free
#=> true

REEXAMINE THE SOURCE FILE IT IT’S STILL THERE

NO, IT IS NOT THERE ANYMORE!

system “dir \test\test1\test2\testfile.txt”
Volume in drive C is hd
Volume Serial Number is 7CD8-B514

Directory of C:\test\test1\test2

File Not Found
#=> false

SUCCESS!, RIGHT?

kind regards -botp

I’ve read elsewhere that on XP, if you have a filehandle open, the move
will fail.

My own experience was that using UNC paths worked where Windows-style
did not.

I am using a UNC path to iterate through the folder structure (to get
all the text files (i.e. pattern matching against *.txt)), and then I’m
doing a move and rename all in one, using Windows-style paths.

When my declaration was localdir = ImportDirName+folder, I got the
permission error.

ImportDirName = “C:\Dev\FKPConversion\Text\”
RenamedDirName = “C:\Dev\FKPConversion\TextProcessed\”
ImportUNCName = “\\c0151\Text\”
foldercount = 0
File.open(ImportListName).each { |line|
folder = line.chomp
unc = ImportUNCName + folder
localdir = ImportUNCName+folder
Dir.chdir(localdir) do
Dir.glob("*.txt").each { |interest|
strippedfile = interest.gsub(’.txt’,’’)
src=“N:\#{strippedfile}”
dest=“N:\#{folder}”
FileUtils.mv src,dest
}
splitfolder=folder.split(’\’)
endfolder=splitfolder[-1]
puts endfolder
renamesrc="#{ImportDirName}#{folder}"
renamedest="#{RenamedDirName}#{endfolder}_#{foldercount}"
FileUtils.mv renamesrc, renamedest
foldercount+=1
end

Hope this helps, Nick.

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