2

I am currently developing a QGis plugin and I need to create and remove directories and I use PyQt. I don't know if my problem comes from PyQt or QGis. So my program creates folders, that works all good smoothly and stuff wow cool XD, then I can remove the empty folders with rmdir from QDir, that works too. the problem comes when there is files in the folder... In order to remove the non empty folders I first remove the files within using the QDir's remove method, that works fine all the files burns in hell and when I want to remove the folder, the rmdir method return True, like if everything was perfect but in fact no XD the folder's still here and became like "blocked" and I can't remove it from the program nor from windows "manually" ! And then only when I exit QGis, all the deletions are applied... I don't know where it comes from... I guess it's because of something like the directory is used by QGis but I don't know... so if you want to see the code ask for it because it's big and I didn't want to throw evrything ^^

10
  • 1
    Using the shutil module, does shutil.rmtree(myDir) delete the folder/files?
    – artwork21
    Apr 11, 2016 at 12:56
  • Yeah forgot to say that I also tried the exact same problem apears...
    – Yorokobii
    Apr 11, 2016 at 13:10
  • Have you tried del myDir before applying shutil.rmtree(myDir)?
    – Joseph
    Apr 11, 2016 at 13:19
  • but if i do that myDir will be None when i'll do the sutil.rmtree(myDir) no? then i don't see the point...
    – Yorokobii
    Apr 11, 2016 at 13:33
  • @Yorokobii - Apologies, you're right, I meant shutil.rmtree('path/to/myDir') where you define the path explicitly but I don't think this would be useful in a plugin.
    – Joseph
    Apr 11, 2016 at 13:53

1 Answer 1

1

Okaaayy I found ! the problem comes from the Qgis browser... the thing where you can explore your folders and stuff... If the folder you want to delete is opened in there it wont delete it... so I just need to find a way to ensure that the folder is not opened in the browser !

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.