Sep-27-2021, 01:22 PM
(Sep-27-2021, 12:44 PM)dyerlee91 Wrote: I'm very much a novice, so apologies if this doesn't make sense.Yes it make sense,but you should give try with some code then you show some effort and easier to help.
Here a couple of examples using pathlib
import pathlib lst = [] mydir = r'G:\div_code\answer\weather' for file in pathlib.Path(mydir).iterdir(): if file.is_file(): lst.append(file.name)
>>> lst ['file_1_0_.txt', 'file_33.txt', 'key.ini', 'open_weather.py', 'to_zip.txt'] >>> >>> for file in lst: ... print(f'{mydir}{file}') ... G:\div_code\answer\weatherfile_1_0_.txt G:\div_code\answer\weatherfile_33.txt G:\div_code\answer\weatherkey.ini G:\div_code\answer\weatheropen_weather.py G:\div_code\answer\weatherto_zip.txtSo over generate absolute path for files in the list.
If remove
.name
then get absolute path with one go.import pathlib lst = [] mydir = r'G:\div_code\answer\weather' for file in pathlib.Path(mydir).iterdir(): if file.is_file(): lst.append(file)
>>> lst [WindowsPath('G:/div_code/answer/weather/file_1_0_.txt'), WindowsPath('G:/div_code/answer/weather/file_33.txt'), WindowsPath('G:/div_code/answer/weather/key.ini'), WindowsPath('G:/div_code/answer/weather/open_weather.py'), WindowsPath('G:/div_code/answer/weather/to_zip.txt')]