SoFunction
Updated on 2024-11-13

Python's way of completely deleting a folder and its subfiles.

I'll cut to the chase and get right to the code!

#coding:utf-8
import os
import stat
import shutil
#filePath:folder path
def delete_file(filePath):
 if (filePath):
  for fileList in (filePath):
   for name in fileList[2]:
    ((fileList[0],name), stat.S_IWRITE)
    ((fileList[0],name))
  (filePath)
  return "delete ok"
 else:
  return "no filepath"
 
print ("E:\\biancheng\\python\\ascas") 
print delete_file("E:\\biancheng\\python\\ascas")

This Python way to completely delete a folder and its sub-files is all that I have shared above, I hope it will give you a reference, and I hope you will support me more.