I searched and found the below code which was written in python to find and delete the empty folders in the drive. when i try to delete the folders, it is giving the error message below. Can i have the modified code or idea to search and delete corrupt folders and files in the drive.
import os
for root, dirs, files in os.walk('//run//media//halovivek//testing'):
for file in files:
src_file = os.path.join(root, file)
if os.path.getsize(src_file) == 0:
os.remove(src_file)
dir_list = []
for root, dirs, files in os.walk('//run//media//halovivek//testing'):
dir_list.append(root)
for root in dir_list[::-1]:
if not os.listdir(root):
os.rmdir(root)
Error Message:
Traceback (most recent call last):
File "/home/halovivek/PycharmProjects/pythonProject/deleteEmpty.py", line 5, in <module>
if os.path.getsize(src_file) == 0:
File "/usr/lib/python3.9/genericpath.py", line 50, in getsize
return os.stat(filename).st_size
OSError: [Errno 5] Input/output error: '//run//media//halovivek//testing/.Trash-1000/files/Songs Folder/My Music/SAD = UNNA NENA.mp3'
Process finished with exit code 1