Demo1 Py
Demo1 Py
import os.path as op
while True:
print("1) Create a File")
print("2) Open and Read")
print("3) Append to File")
print("4) Delete File")
option = int(input("Select One option :"))
if option == 1:
fname = input("Enter File Name :")
if op.exists(fname):
print("File is Available")
else:
open(fname,"a")
print("File is Created")
elif option == 2:
fname = input("Enter File Name :")
if op.exists(fname):
list = open(fname,"r").readlines()
if list:
for x in list:
print(x)
else:
print("File is Empty")
else:
print("File not Available")
elif option == 3:
fname = input("Enter File Name :")
if op.exists(fname):
text = input("Enter Text to File")
file = open(fname,"a")
file.write(text)
file.close()
print("Given Text Written to File")
else:
print("File not Available")
elif option == 4:
fname = input("Enter File Name :")
if op.exists(fname):
os.remove(fname)
print("File is Removed")
else:
print("File not Available")
else:
print("Please select from menu Only")