Код: Выделить всё
os.remove()
Код ниже: < /p>
Код: Выделить всё
def DeleteCheckedFiles(self):
for row in range(self.CheckboxesTable.rowCount()):
item = self.CheckboxesTable.item(row, 0)
if item.checkState() == Qt.Checked:
item_file_path = item.text()
try:
if os.path.isdir(item_file_path):
for root, dirs, files in os.walk(item_file_path, topdown=False):
for name in files:
os.remove(os.path.join(root, name))
for name in dirs:
dir_path = os.path.join(root, name)
if not os.listdir(dir_path): # Check if the directory is empty
os.rmdir(dir_path)
else:
shutil.rmtree(dir_path)
os.rmdir(item_file_path) # Remove the top-level directory
else:
os.remove(item_file_path)
print(f"Deleted: {item_file_path}")
except PermissionError as e:
self.OutputBox.append(f"Error deleting {item_file_path}:\n{e}. \nPlease check permissions or close any open handles.")
else:
self.OutputBox.append("Select an analysis folder and process it before starting a delete and transfer\n")
Подробнее здесь: https://stackoverflow.com/questions/795 ... irectories