KEMBAR78
Demo1 Py | PDF
0% found this document useful (0 votes)
51 views2 pages

Demo1 Py

The document is a Python script that provides a simple command-line interface for file management operations including creating, reading, appending, and deleting files. Users can select options to perform these actions, and the script checks for file existence before proceeding. The loop continues until the user decides to exit by entering a different option.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views2 pages

Demo1 Py

The document is a Python script that provides a simple command-line interface for file management operations including creating, reading, appending, and deleting files. Users can select options to perform these actions, and the script checks for file existence before proceeding. The loop continues until the user decides to exit by entering a different option.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

import os

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")

ans = int(input("To Continue Press 1 :"))


if ans == 1:
continue
else:
break
print("Thanks")

You might also like