newbie permission problem

A

Ann

I am new to python. I have a small program that
deletes small jpeg files, but I am getting a
permission error, even though I am the owner of the
file and the directory has 777 permission. I have
WIN XP Pro. I have mks toolkit "ls" command.
Login name is "Philip"

-------------

36 45 border_l_r2_c3.gif is tiny <- printed by program
Traceback (most recent call last):
File "C:\test2.py", line 28, in ?
os.remove(d) # delete the tiny files
OSError: [Errno 13] Permission denied: 'border_l_r2_c3.gif'

C:\>ls -ld . border_l_r2_c3.gif
drwxrwsrwx 1 Philip None 0 Oct 2 23:40 .
-rwxrwxrwa 1 Philip None 398 Oct 2 22:42 border_l_r2_c3.gif
 
S

Sol Mumey

Ann said:
I am new to python. I have a small program that
deletes small jpeg files, but I am getting a
permission error, even though I am the owner of the
file and the directory has 777 permission. I have
WIN XP Pro. I have mks toolkit "ls" command.
Login name is "Philip"

-------------

36 45 border_l_r2_c3.gif is tiny <- printed by program
Traceback (most recent call last):
File "C:\test2.py", line 28, in ?
os.remove(d) # delete the tiny files
OSError: [Errno 13] Permission denied: 'border_l_r2_c3.gif'

C:\>ls -ld . border_l_r2_c3.gif
drwxrwsrwx 1 Philip None 0 Oct 2 23:40 .
-rwxrwxrwa 1 Philip None 398 Oct 2 22:42 border_l_r2_c3.gif
Are you sure that the unix-style permission reported by ls are
reflecting the true permissions (and read only attribute) on the file.
We use Cygwin at work, at the permissions reported by ls, etc. are
meaningless with our installation (though that need not be the case with
Cygwin). From the commandline I think you can check/set this with
attrib.exe, if a bunch need to be checked/changed.
 
A

Ann

Sol Mumey said:
Ann said:
I am new to python. I have a small program that
deletes small jpeg files, but I am getting a
permission error, even though I am the owner of the
file and the directory has 777 permission. I have
WIN XP Pro. I have mks toolkit "ls" command.
Login name is "Philip"

-------------

36 45 border_l_r2_c3.gif is tiny <- printed by program
Traceback (most recent call last):
File "C:\test2.py", line 28, in ?
os.remove(d) # delete the tiny files
OSError: [Errno 13] Permission denied: 'border_l_r2_c3.gif'

C:\>ls -ld . border_l_r2_c3.gif
drwxrwsrwx 1 Philip None 0 Oct 2 23:40 .
-rwxrwxrwa 1 Philip None 398 Oct 2 22:42 border_l_r2_c3.gif
Are you sure that the unix-style permission reported by ls are
reflecting the true permissions (and read only attribute) on the file.
We use Cygwin at work, at the permissions reported by ls, etc. are
meaningless with our installation (though that need not be the case with
Cygwin). From the commandline I think you can check/set this with
attrib.exe, if a bunch need to be checked/changed.

Yes, I'm not so sure about the output of "ls" myself. (note the 'a'
where I would expect an 'x' for the file) I did try the
attrib command, but it only showed that the directory is "system"
and the file is "archive". Also, I created the file via under my
account (ls shows owner = Philip) and I can delete it manually with
"rm" or "del" or with a perl script just fine. I also tried using
"os.unlink(d)" with the same results. I found another command
lsacl to list the access control list, it gives this: (YOGA is my
workstation name)

C:\>lsacl border-l-r2-c3.gif
border-l-r3-c3[1].gif:
ACE: Allow YOGA\Philip -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
ACE: Allow NT+AUTHORITY\SYSTEM -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
ACE: Allow BUILTIN\Administrators -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
 
A

Ann

Ann said:
Sol Mumey said:
Ann said:
I am new to python. I have a small program that
deletes small jpeg files, but I am getting a
permission error, even though I am the owner of the
file and the directory has 777 permission. I have
WIN XP Pro. I have mks toolkit "ls" command.
Login name is "Philip"

-------------

36 45 border_l_r2_c3.gif is tiny <- printed by program
Traceback (most recent call last):
File "C:\test2.py", line 28, in ?
os.remove(d) # delete the tiny files
OSError: [Errno 13] Permission denied: 'border_l_r2_c3.gif'

C:\>ls -ld . border_l_r2_c3.gif
drwxrwsrwx 1 Philip None 0 Oct 2 23:40 .
-rwxrwxrwa 1 Philip None 398 Oct 2 22:42 border_l_r2_c3.gif
Are you sure that the unix-style permission reported by ls are
reflecting the true permissions (and read only attribute) on the file.
We use Cygwin at work, at the permissions reported by ls, etc. are
meaningless with our installation (though that need not be the case with
Cygwin). From the commandline I think you can check/set this with
attrib.exe, if a bunch need to be checked/changed.

Yes, I'm not so sure about the output of "ls" myself. (note the 'a'
where I would expect an 'x' for the file) I did try the
attrib command, but it only showed that the directory is "system"
and the file is "archive". Also, I created the file via under my
account (ls shows owner = Philip) and I can delete it manually with
"rm" or "del" or with a perl script just fine. I also tried using
"os.unlink(d)" with the same results. I found another command
lsacl to list the access control list, it gives this: (YOGA is my
workstation name)

C:\>lsacl border-l-r2-c3.gif
border-l-r3-c3[1].gif:
ACE: Allow YOGA\Philip -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
ACE: Allow NT+AUTHORITY\SYSTEM -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
ACE: Allow BUILTIN\Administrators -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S

I found the problem just now, the file is still open when I tried
to delete it. If I use

fp = open("filename.jpg", "rb")
im = Image.open(fp)

then I can close fp and delete the file.

How can I just use
im = Image.open("filename.jpg")
without having to use a fp
 
P

Peter Abel

Ann said:
Ann said:
Sol Mumey said:
Ann wrote:
I am new to python. I have a small program that
deletes small jpeg files, but I am getting a
permission error, even though I am the owner of the
file and the directory has 777 permission. I have
WIN XP Pro. I have mks toolkit "ls" command.
Login name is "Philip"

-------------

36 45 border_l_r2_c3.gif is tiny <- printed by program
Traceback (most recent call last):
File "C:\test2.py", line 28, in ?
os.remove(d) # delete the tiny files
OSError: [Errno 13] Permission denied: 'border_l_r2_c3.gif'

C:\>ls -ld . border_l_r2_c3.gif
drwxrwsrwx 1 Philip None 0 Oct 2 23:40 .
-rwxrwxrwa 1 Philip None 398 Oct 2 22:42 border_l_r2_c3.gif


Are you sure that the unix-style permission reported by ls are
reflecting the true permissions (and read only attribute) on the file.
We use Cygwin at work, at the permissions reported by ls, etc. are
meaningless with our installation (though that need not be the case with
Cygwin). From the commandline I think you can check/set this with
attrib.exe, if a bunch need to be checked/changed.

Yes, I'm not so sure about the output of "ls" myself. (note the 'a'
where I would expect an 'x' for the file) I did try the
attrib command, but it only showed that the directory is "system"
and the file is "archive". Also, I created the file via under my
account (ls shows owner = Philip) and I can delete it manually with
"rm" or "del" or with a perl script just fine. I also tried using
"os.unlink(d)" with the same results. I found another command
lsacl to list the access control list, it gives this: (YOGA is my
workstation name)

C:\>lsacl border-l-r2-c3.gif
border-l-r3-c3[1].gif:
ACE: Allow YOGA\Philip -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
ACE: Allow NT+AUTHORITY\SYSTEM -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
ACE: Allow BUILTIN\Administrators -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S

I found the problem just now, the file is still open when I tried
to delete it. If I use

fp = open("filename.jpg", "rb")
im = Image.open(fp)

then I can close fp and delete the file.

How can I just use
im = Image.open("filename.jpg")
without having to use a fp

The following works for me though it's a long way round:
I had expected that the following would work too, but it doesn't:Traceback (most recent call last):
File "<interactive input>", line 1, in ?
OSError: [Errno 13] Permission denied: 'filename.jpg'

My opinion is that Image.open( filepointer ) binds the filpointer-object
to a name while StringIO doesn't and the garbagecollector will close the file.

BTW why do you open an imagefile when you want to delete it? If you want to
decide by view which imagefile should be deleted it would be good practice
to open the imagefile, load the image and then close the file.

Regards
Peter
 
A

Ann

Peter Abel said:
"Ann" <[email protected]> wrote in message
Ann said:
Ann wrote:
I am new to python. I have a small program that
deletes small jpeg files, but I am getting a
permission error, even though I am the owner of the
file and the directory has 777 permission. I have
WIN XP Pro. I have mks toolkit "ls" command.
Login name is "Philip"

-------------

36 45 border_l_r2_c3.gif is tiny <- printed by program
Traceback (most recent call last):
File "C:\test2.py", line 28, in ?
os.remove(d) # delete the tiny files
OSError: [Errno 13] Permission denied: 'border_l_r2_c3.gif'

C:\>ls -ld . border_l_r2_c3.gif
drwxrwsrwx 1 Philip None 0 Oct 2 23:40 .
-rwxrwxrwa 1 Philip None 398 Oct 2 22:42 border_l_r2_c3.gif


Are you sure that the unix-style permission reported by ls are
reflecting the true permissions (and read only attribute) on the file.
We use Cygwin at work, at the permissions reported by ls, etc. are
meaningless with our installation (though that need not be the case with
Cygwin). From the commandline I think you can check/set this with
attrib.exe, if a bunch need to be checked/changed.

Yes, I'm not so sure about the output of "ls" myself. (note the 'a'
where I would expect an 'x' for the file) I did try the
attrib command, but it only showed that the directory is "system"
and the file is "archive". Also, I created the file via under my
account (ls shows owner = Philip) and I can delete it manually with
"rm" or "del" or with a perl script just fine. I also tried using
"os.unlink(d)" with the same results. I found another command
lsacl to list the access control list, it gives this: (YOGA is my
workstation name)

C:\>lsacl border-l-r2-c3.gif
border-l-r3-c3[1].gif:
ACE: Allow YOGA\Philip -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
ACE: Allow NT+AUTHORITY\SYSTEM -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S
ACE: Allow BUILTIN\Administrators -
R,W,X,A,DC,RE,WE,RA,WA,D,RC,WD,O,S

I found the problem just now, the file is still open when I tried
to delete it. If I use

fp = open("filename.jpg", "rb")
im = Image.open(fp)

then I can close fp and delete the file.

How can I just use
im = Image.open("filename.jpg")
without having to use a fp

The following works for me though it's a long way round:
I had expected that the following would work too, but it doesn't:Traceback (most recent call last):
File "<interactive input>", line 1, in ?
OSError: [Errno 13] Permission denied: 'filename.jpg'

My opinion is that Image.open( filepointer ) binds the filpointer-object
to a name while StringIO doesn't and the garbagecollector will close the file.

BTW why do you open an imagefile when you want to delete it? If you want to
decide by view which imagefile should be deleted it would be good practice
to open the imagefile, load the image and then close the file.

Regards
Peter

Peter, I only want to find out the dimensions of the file.
I have a huge number of jpg files and I want to automatically
delete the tiny ones.
Tnx for help.
 
P

Peter L Hansen

Ann said:
I found the problem just now, the file is still open when I tried
to delete it. If I use

fp = open("filename.jpg", "rb")
im = Image.open(fp)

then I can close fp and delete the file.

How can I just use
im = Image.open("filename.jpg")
without having to use a fp

I would ask why you would want to do it without using
an "fp". The fp solution is more readable (to another
programmer, that is), more portable, and besides, it
works, so why look for a possibly more complicated
alternative just to avoid using "fp"?
 
A

Ann

Peter L Hansen said:
I would ask why you would want to do it without using
an "fp". The fp solution is more readable (to another
programmer, that is), more portable, and besides, it
works, so why look for a possibly more complicated
alternative just to avoid using "fp"?

Probably cuz I'm new to python and I saw an example in
the documentation that did it without fp. As you say,
fp makes more sense and I am using it now.
 
P

Peter Abel

Ann said:
"Peter Abel" <[email protected]> wrote in message

...
...
... [snip]
The following works for me though it's a long way round:
jpeg='filename.jpg'
import cStringIO
im=Image.open(cStringIO.StringIO(file(jpeg,'rb').read()))
os.remove(jpeg)

I had expected that the following would work too, but it doesn't:
im=Image.open(file(jpeg,'rb'))
os.remove(jpeg)
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
OSError: [Errno 13] Permission denied: 'filename.jpg'

My opinion is that Image.open( filepointer ) binds the filpointer-object
to a name while StringIO doesn't and the garbagecollector will close the file.

BTW why do you open an imagefile when you want to delete it? If you want to
decide by view which imagefile should be deleted it would be good practice
to open the imagefile, load the image and then close the file.

Regards
Peter

Peter, I only want to find out the dimensions of the file.
I have a huge number of jpg files and I want to automatically
delete the tiny ones.
Tnx for help.

OK, for this there is no need to open the files.
The following function should do it:
.... files=map(lambda lfn:\
.... (os.path.getsize(lfn),lfn),\
.... glob.glob(os.path.join(path,file_mask))\
.... )
.... for (s,f) in files:
.... if s < limit_size:
.... print 'os.remove(%s): size: %d' % (f,s)
....
os.remove(.\quiet.py): size: 1339
os.remove(.\Client.py): size: 923
os.remove(.\show_vblpc.py): size: 5411
os.remove(.\tcpBetriebsbild.py): size: 37737

Regards
Peter
 

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,744
Messages
2,569,479
Members
44,899
Latest member
RodneyMcAu

Latest Threads

Top