File manager
Welcome to file manager.
This is file manager code you can file create, edit, read, delete. import os module.
import os
def create_file(filename):
with open(filename, 'w') as file:
print("File created:", filename)
def read_file(filename):
try:
with open(filename, 'r') as file:
print("Content of", filename, ":")
print(file.read())
except FileNotFoundError:
print("File not found.")
def update_file(filename):
try:
with open(filename, 'a') as file:
text = input("Enter text to append: ")
file.write(text + "\n")
print("Text appended to", filename)
except FileNotFoundError:
print("File not found.")
def delete_file(filename):
try:
os.remove(filename)
print("File deleted:", filename)
except FileNotFoundError:
print("File not found.")
def file_manager():
while True:
print("\nFile Management System")
print("1. Create File")
print("2. Read File")
print("3. Update File")
print("4. Delete File")
print("5. Exit")
choice = input("Enter your choice (1-5): ")
if choice == '5':
print("Exiting...")
break
filename = input("Enter filename: ")
if choice == '1':
create_file(filename)
elif choice == '2':
read_file(filename)
elif choice == '3':
update_file(filename)
elif choice == '4':
delete_file(filename)
else:
print("Invalid choice. Please try again.")
if __name__ == "__main__":
file_manager()
Comments