Ошибка returned non-zero exit status 1. в Python
Код:
import subprocess
directory = r'C:/Windows/Temp'
file_list = os.listdir(directory)
for file_name in file_list:
file_path = os.path.join(directory, file_name)
if os.path.isfile(file_path):
os.chmod(file_path, 0o777)
try:
subprocess.run(['cmd', '/c', 'del', file_path], check=True)
except subprocess.CalledProcessError as e:
print(f"Не удалось удалить файл {file_path}: {e}")
for file_name in file_list:
file_path = os.path.join(directory, file_name)
if os.path.isdir(file_path):
os.chmod(file_path, 0o777)
try:
subprocess.run(['cmd', '/c', 'rd', '/s', '/q', file_path], check=True)
except subprocess.CalledProcessError as e:
print(f"Не удалось удалить папку {file_path}: {e}")
Вывод в консоли:
Не удалось удалить файл C:/Windows/Temp\4e3d0a21-4f4b-4280-9969-e757dbb64476.tmp: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\4e3d0a21-4f4b-4280-9969-e757dbb64476.tmp']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\538cdcdf-b029-450e-8187-592bbb068d6d.tmp: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\538cdcdf-b029-450e-8187-592bbb068d6d.tmp']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\622691a5-ce2c-4425-a191-34fde3ff7ce4.tmp: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\622691a5-ce2c-4425-a191-34fde3ff7ce4.tmp']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\8b0562b4-7d5c-4ee6-bb53-cc398b1efd77.tmp: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\8b0562b4-7d5c-4ee6-bb53-cc398b1efd77.tmp']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\9d63ae88-b536-4a81-8959-31f323122ac6.tmp: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\9d63ae88-b536-4a81-8959-31f323122ac6.tmp']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\api-ms-win-crt-runtime-l1-1-0.dll: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\api-ms-win-crt-runtime-l1-1-0.dll']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\b26e7106-e94d-41bb-ba7f-88a2aa8a7051.tmp: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\b26e7106-e94d-41bb-ba7f-88a2aa8a7051.tmp']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\cleaner.py: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\cleaner.py']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\cleaner2.py: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\cleaner2.py']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\cleaner3.py: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\cleaner3.py']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\cleaner4.py: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\cleaner4.py']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\d36fa3c9-cff0-477f-85df-f09403ce1391.tmp: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\d36fa3c9-cff0-477f-85df-f09403ce1391.tmp']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\FXSAPIDebugLogFile.txt: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\FXSAPIDebugLogFile.txt']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\messagebox.py: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\messagebox.py']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\v2.pyw: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\v2.pyw']' returned non-zero exit status 1.
Не удалось удалить файл C:/Windows/Temp\wsc_agent_legacy_9E1C8D64_E25A_431A_9C7D_FA4605A88234.log: Command '['cmd', '/c', 'del', 'C:/Windows/Temp\\wsc_agent_legacy_9E1C8D64_E25A_431A_9C7D_FA4605A88234.log']' returned non-zero exit status 1.
Не удалось удалить папку C:/Windows/Temp\sentry_temp: Command '['cmd', '/c', 'rd', '/s', '/q', 'C:/Windows/Temp\\sentry_temp']' returned non-zero exit status 1.```
Источник: Stack Overflow на русском