I am looking to delete files from multiple folders using a .csv file. The csv file contains a list of file names that need to be deleted(example: Box4, 60012-01). How the data is stored is in multiple folder and also had additional extension (example: /tiles_20X_299/Box20/660491-3_mag20_xpos5980_ypos6279.jpg. Is there a way to get these files deleted. Help would be really appreciated. This is what I have till now but not sure if I'm going the right direction. [sample of the csv file to delete][1]
fin = open('files_to_delete.csv', 'r')
fin.readline()
print(fin)
file_to_delete = set()
while True:
line = fin.readline().strip()
#print(line)
if not line:
break
array = line.split(',')
file_to_delete.add("Box" + array[0] + "/" + array[1])
fin.close()
print(file_to_delete)
#
for path in glob.glob('/home/sshah/Tiles/tiles_20X_299/*'):
for f in file_to_delete:
print(f)
os.chdir(path)
#print(path)
if os.path.exists(f):
print('delete')
#os.remove(f)```
[1]: https://i.stack.imgur.com/dFCxk.png