-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreadFiles.py
35 lines (29 loc) · 863 Bytes
/
readFiles.py
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
35
import os
def read_file(filepath):
"""
Reads the contents of a file and returns them as a string.
Args:
filepath: The path to the file to read.
Returns:
The contents of the file as a string, or None if there's an error.
"""
try:
with open(filepath, 'r') as file:
# Read the entire file
contents = file.read()
return contents
except FileNotFoundError:
print(f"Error: File not found: {filepath}")
except PermissionError:
print(f"Error: Insufficient permissions to read file: {filepath}")
except Exception as e:
print(f"Error reading file: {filepath} - {e}")
return None
# Example usage
filepath = "/bbb//Downloadsbbb/Debian_update.sh" # Replace with the actual path
contents = read_file(filepath)
if contents:
print("File contents:")
print(contents)
else:
print("Failed to read file.")