Re: Searching for a file
"Peter J. Holzer" <[email protected]>
| Newsgroups | gmane.comp.python.general |
|---|---|
| Message-ID | <[email protected]> |
On 2025-05-28 10:59:16 +0300, Roland Mueller via Python-list wrote: > ke 28.5.2025 klo 1.45 Thomas Passin ([email protected]) 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 -- _ | Peter J. Holzer | Story must make more sense than reality. |_|_) | | | | | [email protected] | -- Charles Stross, "Creative writing __/ | http://www.hjp.at/ | challenge!"
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEETtJbRjyPwVTYGJ5k8g5IURL+KF0FAmg2140ACgkQ8g5IURL+ KF2RJw//UVuR/hMS7UkSdvQU79KAAtrtfK7zheu1AslDWt+bCpwYD3FpUq6yMOtD Tc381uTaVVOOdxxsjgUX7h/t4qS7LYOfYfd2LtZ6120cS30wSJFq0g9HrTUMisQU FAMOj/s2KFf89WMjh4EiVt+NG2uLGt1NT0QRr+2Qhj94ZvqY2vHSfswIyNqTEI8A kzdYRkt4HKMnvYUvr/3ljG7UIem8EdiqHpGTjnaUV8YsEIk4WkDeB+/SSGSnJ9NN 0tlmikEySsnga4rAHkM4cNrQtt1LKco/wdEhceutzYYXCS/KcYsVJJsfAteK1WRB Qzx9ghTSSHUwsVWloSVnST4LPr36n1t+NfbUp9R6f0D5e/yzrk5KtA6Q/sqztHze TruSZQZvXGMgclUCixunpoXGkP97hGjFXjVHhaLUb6P1XEJAcIZ7VZUSIqg8pI1J A6ab4lbnQwnNv7JJSOceh463Z8Os35f0ZVdSqk58m7TiVbLo2TU4MDus8zMPIskm mK0D6mxpsjXWSnptp8eNKy60poNJtuCerqfD34su2irMrF94rJVjLRsvp+8ddCVx nmRJjGs6D9WW6OMcCqGZ0d/yVpwRePOPpsIo4rOqL15SwBo6JYfVAQG/8qGPScz6 4eWm6S+9WGoMm9dXxg1uUcPISpXm4Dt1hd7acimPg3Ge4mrKn/w= =Qzwp -----END PGP SIGNATURE-----