(Aug-20-2024, 01:31 PM)RRADC Wrote: Probably another dumb question but what does this "if 'url_sample.csv'" do for this script?I just put in a random file to test delete from this system folder.
If i should delete folders eg
Temp
i would do it like this,see that i do not use .join()
as pathlib always give absolute path.Also as info this code dos recursive search of all file/folders,so it work the same as
os.walk
. from pathlib import Path, PurePath import os import shutil folder_path = r'C:\Program Files (x86)\Microsoft' for file_path in Path(folder_path).rglob('*'): if file_path.is_dir(): if 'Temp' in file_path.parts: print(file_path) shutil.rmtree(file_path)So it work fine and delete Temp folder with all content.
Output:G:\div_code\reader_env
λ python del_folders.py
C:\Program Files (x86)\Microsoft\BingSvc\Temp
C:\Program Files (x86)\Microsoft\Edge\Temp
C:\Program Files (x86)\Microsoft\Edge\Temp\scoped_dir41564_1447529849