Delete file & directory

#!/usr/bin/evn python 

import os
directory = input("Enter your directory name: ")
# Check if directory exist or not
if os.path.exists(directory):
    # Delete directory from current location
    print(directory," - directory successfully deleted!")
    print("Directory ",directory," doesn't exists!")
fileName = input("Enter your file name: ")

# Check if file exist or not
if os.path.exists(fileName):
    # Delete file  from current location
    print(fileName," - file successfully deleted!")
    print("File ",directory," doesn't exists!")

#***** Output *****
Enter your directory name: abcd
abcd  - directory successfully deleted!
Enter your file name: safd.txt
File  abcd  doesn't exists!

Comments (0)

  • To add your comment please or

We use cookies to improve your experience on our site and to show you personalised advertising. Please read our cookie policy and privacy policy.

Got It!