I'm taking a directory as an input and recursively searching through it for specific files with specific extensions, and directories (subdirectories) with specific names. As I understand it, shutil.rmtree() recursively searches through a directory and deletes everything in it (I have topdown disabled, so it starts at the end). However, this doesn't work for empty directories. For those cases, I'm using os.rmdir() to remove the empty directories it encounters/creates when it deletes everything inside of it. os.remove() is used when files are encountered. The problem: None of the empty directories are being deleted, and I continue to get a permission error when attempting to delete them. All files are stored in the same place, so a permissions issue shouldn't exist. Code below: 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") The item_file_path comes from a QTDesigner QTableWidgetItem widget and is just the full file path of the targeted files and directories. Continue reading...