On 5/28/25 03:29, Peter J. Holzer wrote:
On 2025-05-28 10:59:16 +0300, Roland Mueller via Python-list wrote:
ke 28.5.2025 klo 1.45 Thomas Passin (li...@tompassin.net) kirjoitti:
On 5/27/2025 10:41 AM, Roland Mueller via Python-list wrote:
To get a list of files in a given directory one can use glob.glob and

The OP had a different problem.  He wanted to find a config file of
known name that could be in one of several locations.


This can be done by replacing the star wildcard  the join(dir, '*') with a
filename or filename glob pattern.
tmp_files = []
for dir in ['/tmp', '/var/tmp']:
...     tmp_files += [f for f in glob(join(dir, filename_to_find))  if
isfile(f) ]

But then the glob is useless.

Just try to open the file as Chris already demonstrated.

         hjp



Indeed - a simple loop over the possible dirs each concatenated with the known file name is quick and easy.

Was only responding on the glob/pathlib stuff as there seemed to be information missing, not to claim it was necessarily a better solution for this need (could still be used, though).
--
https://mail.python.org/mailman3//lists/python-list.python.org

Reply via email to