-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfile_processor.py
More file actions
34 lines (27 loc) · 1.33 KB
/
Copy pathfile_processor.py
File metadata and controls
34 lines (27 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
def process_file():
try:
# Ask user for input filename
input_filename = input("Enter the name of the file to read: ")
# Try to open and read the input file
with open(input_filename, 'r') as input_file:
content = input_file.read()
# Modify the content (in this example, we'll capitalize it)
modified_content = content.upper()
# Create output filename by adding 'modified_' prefix
output_filename = f"modified_{input_filename}"
# Write modified content to new file
with open(output_filename, 'w') as output_file:
output_file.write(modified_content)
print(f"\nSuccess! Modified content has been written to {output_filename}")
except FileNotFoundError:
print(f"\nError: The file '{input_filename}' was not found.")
except PermissionError:
print(f"\nError: Permission denied to access the file '{input_filename}'.")
except IOError as e:
print(f"\nError: An I/O error occurred: {str(e)}")
except Exception as e:
print(f"\nError: An unexpected error occurred: {str(e)}")
if __name__ == "__main__":
print("File Processing Program")
print("----------------------")
process_file()