Попытка удалить все файлы, кроме одного, в данном каталоге. Посмотрел другие похожие сообщения, но мой вопрос, похоже, касается получения имен из os.listdir и необходимости полного пути с расширениями для использования os.remove:
Код: Выделить всё
# delete files from the save path but preserve the zip file
if os.path.isfile(zip_path):
for clean_up in os.listdir(data_path):
if not clean_up.endswith(tStamp+'.zip'):
os.remove(clean_up)
Код: Выделить всё
Line 5: os.remove(clean_up)
FileNotFoundError: [WinError 2] The system cannot find the file specified: 'firstFileInListName'
What can I do to delete all files from the data_path except for the one that ends with tStamp+'.zip' ?
Источник: https://stackoverflow.com/questions/781 ... ified-find