Removing hidden files and folders with python ...

Discussion in 'Python' started by Konrad Mühler, Jan 30, 2008.

  1. Hi,

    I try to delete a whole directory-tree using shutil.rmtree(...)
    But there are always the hidden files and folders (e.g. from the svn
    ..svn) left.

    How can I delete -all- files and folders (also the hidden) with python?

    Many Thanks
    Konrad
    Konrad Mühler, Jan 30, 2008
    #1
    1. Advertising

  2. On 30 ene, 06:21, Konrad Mühler <-magdeburg.de>
    wrote:

    > I try to delete a whole directory-tree using shutil.rmtree(...)
    > But there are always the hidden files and folders (e.g. from the svn
    > .svn) left.
    >
    > How can I delete -all- files and folders (also the hidden) with python?


    I assume you use Windows.
    You have to reset the "readonly", "system" and "hidden" directory
    attributes. os.chmod can reset the first one, but for the others you
    have to use ctypes or the pywin32 package to call the
    SetFileAttributes function.
    Of course there is system too:
    os.system("attrib -r -h -s filename")

    You could use rmtree once, apply the above on the remaining files and
    directories -if any- and try rmtree again.

    --
    Gabriel Genellina
    Gabriel Genellina, Jan 30, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Antoon Pardon

    Hidden files/folders on Windows

    Antoon Pardon, Nov 25, 2003, in forum: Python
    Replies:
    2
    Views:
    935
    Fredrik Lundh
    Nov 25, 2003
  2. David Pratt
    Replies:
    11
    Views:
    846
    Dennis Lee Bieber
    Mar 9, 2006
  3. Replies:
    5
    Views:
    751
    Juan T. Llibre
    Jan 26, 2007
  4. stacey
    Replies:
    5
    Views:
    347
    Patricia Shanahan
    Mar 14, 2007
  5. Rick
    Replies:
    3
    Views:
    8,139
    Alexey Smirnov
    Apr 13, 2010
Loading...

Share This Page