-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeletefiles.py
36 lines (28 loc) · 929 Bytes
/
deletefiles.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
36
import os
import sys
def delete_file(file_path):
try:
os.remove(file_path)
print(f"Deleted: {file_path}")
except OSError as e:
print(f"Error: {e.strerror}. File: {file_path}")
def process_file(file_name):
try:
with open(file_name, 'r') as file:
for line in file:
# Handle both lineseparated and comma-separated values
file_paths = line.strip().split(',')
for path in file_paths:
if path: # check path is not empty
delete_file(path.strip())
except FileNotFoundError:
print(f'File not found: {file_name}')
except Exception as e:
print(f'Error: {e}')
def main():
if len(sys.argv) !=2:
print("Usage: python script.py <file_path_list.txt")
deletion_list = sys.argv[1]
process_file(deletion_list)
if __name__ == "__main__":
main()