Easiest way to rm -rf in Python

前端 未结 7 1583
忘了有多久
忘了有多久 2020-12-08 12:44

What is the easiest way to do the equivalent of rm -rf in Python?

7条回答
  •  悲&欢浪女
    2020-12-08 13:26

    A workaround for Windows where it blocks deletion of file is to truncate the file:

    outputFile = open(r"filename.txt","w") 
    outputFile.truncate()
    outputFile.close()
    outputFile = open(r"filename.txt","a+") 
    

    source: https://stackoverflow.com/a/2769090/6345724

提交回复
热议问题