How to Delete a File or Folder in Python

🌟 How to Delete a File

import os
os.unlink('C:\\Users\\David\\file.txt')


🌟 How to Delete an Empty Folder (Directory)

import os
os.rmdir('C:\\Users\\David\\PythonProjects')





🌟 How to Delete an Directory (that has empty)

import shutil, os
shutil.rmtree('C:\\Users\\David\\PythonProjects')

❇️ @raspberry_python

Comments

Be the first to add a comment