473,395 Members | 1,532 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

shutil.move, permission denied, why ?


Hello world,

I am fighting with what is probably a stupid problem.

In a wxpython GUI, here is a method which must read a file,
and if the file is not correctly formed rename it and create a new file:

(I have removed most of the logic of the code here, so I am not sure
it's going to be helpful)

def makeTree(self):
print 'HERE WE ARE'
f = file(self.__filename,'r')
f.close()
from shutil import move
from os.path import join
bakname = self.__filename + '.bak'
print bakname
print f.closed
f.close()
print 'TEST',f.closed
move(self.__filename,bakname)
Here is some of the output corresponding to this method
(on cygwin/Windows 2000, with python 2.3.3):

.... in makeTree:

move(self.__filename,bakname)
File "e:\Program\Python\lib\shutil.py", line 171, in move
os.unlink(src)
OSError: [Errno 13] Permission denied: u'C:\\home\\natasha\\stephane\\PYTHON
\\Projects\\Scripts\\config.xml'

python -V
Python 2.3.3

I just do not understand what could cause this "permissions denied" for this
file. Any idea of what stupid thing I could have done somewhere in the code
that could cause that ?
Thanks in advance for any suggestion...

Regards,

--
Stephane Ninin

Jul 18 '05 #1
7 13930
"Stéphane Ninin" <st*****@alussinan.org> writes:
[...]
(I have removed most of the logic of the code here, so I am not sure
it's going to be helpful)

[...]

Post a short snippet of code that runs and demonstrates the problem.
John
Jul 18 '05 #2
Stéphane Ninin wrote:
I just do not understand what could cause this "permissions denied" for this
file. Any idea of what stupid thing I could have done somewhere in the code
that could cause that ?


Can you do exactly the same thing successfully from the command
line? That is, do a "move a b" with the same paths that you
are trying to use in your code?
Jul 18 '05 #3
> def makeTree(self):
print 'HERE WE ARE'
f = file(self.__filename,'r')
f.close()
from shutil import move
from os.path import join
bakname = self.__filename + '.bak'
print bakname
print f.closed
f.close()
print 'TEST',f.closed
move(self.__filename,bakname)


Try... os.rename(self.__filename, bakname)

- Josiah
Jul 18 '05 #4
Also sprach Peter Hansen :
I just do not understand what could cause this "permissions denied" for
this file. Any idea of what stupid thing I could have done somewhere in
the code that could cause that ?


Can you do exactly the same thing successfully from the command
line? That is, do a "move a b" with the same paths that you
are trying to use in your code?

A short test script is working correctly, but I will try to write something
bigger and post it here later.

Jul 18 '05 #5
Also sprach John J. Lee :
(I have removed most of the logic of the code here, so I am not sure
it's going to be helpful)

[...]

Post a short snippet of code that runs and demonstrates the problem.


Ok, I have reduced it, but I am afraid problem comes from PyXML...

You must have some file called "test.xml "
(file is empty in my test) in the same directory as the script:
def getFileName():
from os.path import abspath,join
from sys import path
cdir = abspath(path[0])
cfile = join(cdir,'test.xml')
return cfile

from xml.sax.saxutils import DefaultHandler

class TestReader(object):

def __init__(self):
pass

def read(self,filename):

from _xmlplus.sax.sax2exts import XMLValParserFactory
parser = XMLValParserFactory.make_parser()

#from xml.sax.handler import feature_namespaces,feature_validation
#parser.setFeature(feature_namespaces, 0)

dh = DefaultHandler()

parser.setContentHandler(dh)
parser.setErrorHandler(dh)

f = file(filename,'r')

try:
parser.parse(f)
finally:
parser.close()
parser.reset()
f.close()

return 1

def ViewFile():
from xml.sax._exceptions import SAXParseException

infile = getFileName()

a = TestReader()

try:
print 'A0'
pls = a.read(infile)
except SAXParseException,e:
print 'B1'
pls = {}

from shutil import move
from os import rename

bakname = infile + '.bak'
move(infile,bakname)
#rename(infile,bakname)
def main():
ViewFile()

main()

Jul 18 '05 #6
Also sprach Josiah Carlson :

Try... os.rename(self.__filename, bakname)


Thanks for the idea, but unfortunately it doesnot change anything.
Jul 18 '05 #7
"Stéphane Ninin" <st*****@alussinan.org> wrote in message
news:Xn*********************************@212.27.42 .68...
....
I just do not understand what could cause this "permissions denied" for this file. Any idea of what stupid thing I could have done somewhere in the code that could cause that ? .... Stephane Ninin


Hi Stéphane

Some time ago I had a "permission denied" problem on Windows that I finally
tracked down to os.system duplicating open handles at the creation instance!
The method I used to locate the problem area was by having python fire off
an instance of handle.exe (freely available from www.sysinternals.com) when
the permission error occurred to see what else had the file open.

Colin Brown
PyNZ

Jul 18 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: bmgz | last post by:
I am have made a simple script that moves all desktop clutter (ie files that are not *.lnk) to a specified folder eg. c:\myhome\mydocs\desktopdebris\2003-12-16 ...
6
by: Daniel Bickett | last post by:
Hello, I'm writing an application in my pastime that moves files around to achieve various ends -- the specifics aren't particularly important. The shutil module was chosen as the means simply...
1
by: Todd7 | last post by:
I am writing a python program to load a pdf file into an IEHtmlWindow which displays it through adobe acrobat reader 7. Depending on the buttons the user clicks, the program moves it to another...
6
by: Antoine De Groote | last post by:
Google tells quite some things about it, but none of them are satisfactory. I'm on Windows, and shutil operations (e.g. move, copy) throw Permission denied all the time, for the source files. It...
10
by: Robert Dailey | last post by:
Hi, I'm trying to create a Python equivalent of the C++ "ifstream" class, with slight behavior changes. Basically, I want to have a "filestream" object that will allow you to overload the...
0
by: Ahmed, Shakir | last post by:
Is there any way to copy a file from src to dst if the dst is exclusively open by other users. I am using src = 'c:\mydata\data\*.mdb' dst = 'v:\data\all\*.mdb' shutil.copyfile(src,dst)
2
by: Lance Hoffmeyer | last post by:
Hey all, As always, thanks in advance! I am trying to save a ppt presentation but am having problems regarding spaces and am wondering if I am doing something wrong or whether this is a bug?...
4
by: Roopesh | last post by:
Hi, I have a multithreaded application. There are two threads, T1 and T2. Suppose that there are two folders A, B. Thread T1 fetches data from network and creates files in folder A and after...
3
by: unauthorized | last post by:
I'm running a PHP 5.1 on an Apache 2.2 server under Windows XP which I use to develop my web apps. Currently, I am trying to add "upload" functionality to my project, but for some reason, when the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.