newbie permission problem

Ann Anna at nospam.invalid
Sun Oct 3 15:11:51 EDT 2004


"Peter Abel" <PeterAbel at gmx.net> wrote in message
news:21064255.0410030852.34c732cf at posting.google.com...
> "Ann" <Anna at nospam.invalid> wrote in message
news:<azO7d.404372$8_6.311894 at attbi_s04>...
> > "Ann" <Anna at nospam.invalid> wrote in message
> > news:PUN7d.296691$mD.66455 at attbi_s02...
> > >
> > > "Sol Mumey" <smumeyyahoocom at add.dots> wrote in message
> > > news:7sN7d.593248$gE.589623 at pd7tw3no...
> > > > 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:
> >>> 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.





More information about the Python-list mailing list