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

C

Clement Ow

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

Clement Ow

Clement said:
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?
 
C

Clement Ow

Roger said:
double check the directory exists ?
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?
 
N

Nick Romney

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.
 

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

Forum statistics

Threads
473,982
Messages
2,570,190
Members
46,740
Latest member
AdolphBig6

Latest Threads

Top