-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdelete_files.py
More file actions
25 lines (22 loc) · 957 Bytes
/
Copy pathdelete_files.py
File metadata and controls
25 lines (22 loc) · 957 Bytes
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
import csv
import os
import stat
def delete_files_from_csv(csv_path):
with open(csv_path, 'r', newline='', encoding='utf-8') as csv_file:
csv_reader = csv.reader(csv_file)
next(csv_reader) # Skip the header row
for row in csv_reader:
filenames = row[4:] # Assuming filenames are in columns 5 and onwards
for filename in filenames:
try:
# Ensure the file is not read-only
os.chmod(filename, stat.S_IWRITE)
os.remove(filename)
print(f"File deleted: {filename}")
except FileNotFoundError:
print(f"File not found: {filename}")
except Exception as e:
print(f"Error deleting {filename}: {e}")
if __name__ == "__main__":
csv_path = input("Enter the path to the CSV file: ")
delete_files_from_csv(csv_path)