Hello Sateesh Kumar,
Thanks for informative links I learned new things and now problem
is solved!.
On Fri, Oct 28, 2011 at 10:05 AM, Sateesh Kumar <[email protected]>wrote:
> On Fri, Oct 21, 2011 at 12:37 PM, Shashidhar Paragonda <
> [email protected]> wrote:
>
> * Then i tried *shutil.rmtree(path/to/folder/) but here I am
> > facing permission denied error
> >
> > code : os.chmod(path/to/folder, 0777)
> > if os.access(path/to/folder, os.R_OK):
> > shutil.rmtree(path/to/folder/)
> > is there any problem in this code or which is best solution for
> the
> > above requirement.
> >
>
> What you are doing is changing the permission of the folder, but if
> there are files inside that folder which have the 'Read-Only'
> attribute set then their removal would fail and an exception
> thrown. If you examine the stack trace you can find the file whose
> removal attempt failed.
>
> shutil.rmtree can take a function as a callback and you can make use
> of that feature to handle failures in file/subfolder removal and to remove
> them. Such an approach is explained here:
>
>
> http://stackoverflow.com/questions/1213706/what-user-do-python-scripts-run-as-in-windows
>
> http://stackoverflow.com/questions/2656322/python-shutil-rmtree-fails-on-windows-with-access-is-denied
>
> Also when you are passing windows path as an argument to Python
> functions it is better to pass them as raw strings[1]. Your invocation
> should be
> in the form:
>
> os.listdir(r'c:\temp')
> and so on.
>
> HTH,
> sateesh
>
> 1. http://docs.python.org/tutorial/introduction.html (Section 3.1.2
> Strings)
> _______________________________________________
> BangPypers mailing list
> [email protected]
> http://mail.python.org/mailman/listinfo/bangpypers
>
--
-----------------------------------
Regards,
Shashidhar N.Paragonda
[email protected]
+919449073835
_______________________________________________
BangPypers mailing list
[email protected]
http://mail.python.org/mailman/listinfo/bangpypers