import os
import shutil
current_file = os.path.realpath(__file__)
current_directory = os.path.dirname(current_file)
cwd = os.getcwd()
print(current_file)
print(current_directory)
print(cwd)
for file in os.listdir(current_directory):
print(file)
new_directory = current_directory + '/' + 'new-directory'
if not os.path.exists(new_directory):
os.mkdir(current_directory + '/' + 'new-directory')
new_file = new_directory + '/' + 'new-file.txt'
fo = open(new_file, 'w+')
fo.write("Python is a great language.\nYeah its great!!\n")
print("Name of the file: ", fo.name)
fo.close()
os.rename(new_file, new_directory + '/' + 'new-file2.txt')
new_file = new_directory + '/' + 'new-file2.txt'
f = open(new_file, 'r')
print(f.read())
print(f.readline())
decide = input("delete the newly created file? ")
if decide == 'yes' and os.path.isfile(new_file):
os.remove(new_file)
print(new_file + ' deleted')
decide = input("delete the newly created directory? ")
if decide == 'yes' and os.path.exists(new_directory):
os.rmdir(new_directory)
print(new_directory + ' deleted')
decide = input("delete the newly created directory and all files inside? ")
if decide == 'yes' and os.path.exists(new_directory):
shutil.rmtree(new_directory)
print(new_directory + ' and all files inside deleted')