Wed Aug 11 2021
Directory
Python Programming1334 views
File Name: directory-operation.py
#!/usr/bin/evn python
import os
directory = input("Enter your directory name: ")
if not os.path.exists(directory):
# Create directory
os.makedirs(directory)
print(directory," - directory successfully created!")
else:
print("Directory ",directory," already exists!")
print("List all directory under /usr")
# List all directory
print(os.listdir("/usr"))
# Delete directory
os.rmdir(directory)
print(directory," - directory deleted successfully!")
#***** Output *****
# Enter your directory name: abcd
# abcd - directory successfully created!
# List all directory under /usr
# ['include', 'local', 'bin', 'lib', 'src', 'sbin', 'lib64', 'share', 'lib32', 'etc']
# abcd - directory deleted successfully!
Reference:
Author:Geekboots