Re: Searching for a file
"Peter J. Holzer" <[email protected]>
| Newsgroups | gmane.comp.python.general |
|---|---|
| Message-ID | <[email protected]> |
On 2025-08-04 19:22:23 -0600, Michael Torrie via Python-list wrote:
> On 5/24/25 7:19 PM, Chris Angelico via Python-list wrote:
> > for dir in dirs:
> > try: open(dir + "/" + fn).close()
> > except FileNotFoundError: pass
> > else: break
> >
> > Is this really all that difficult? Not everything has to be in the stdlib.
>
> That would modify atime on unix file systems, no?
No, you have to actually read the file for that. Just opening is not
enough:
% ls -lu foo
-rw-r--r-- 1 hjp hjp 56 May 28 10:05 foo
% python3
Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> fh = open("foo")
>>> fh.close()
>>>
% ls -lu foo
-rw-r--r-- 1 hjp hjp 56 May 28 10:05 foo
Still unchanged. But:
% python3
Python 3.12.3 (main, Jun 18 2025, 17:59:45) [GCC 13.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> fh = open("foo")
>>> s = fh.read()
>>> fh.close()
>>>
% ls -lu foo
-rw-r--r-- 1 hjp hjp 56 Aug 9 20:31 foo
Now the atime is changed.
> Of course most modern file systems on SSDs are mounted with noatime,
> but still.
relatime is probably more common. And definitely more useful.
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+KF0FAmiXlPoACgkQ8g5IURL+ KF2ZjQ/9EnG7m4U1FLz+Unzu8/FFGSxgS/vqmynvbq7M6kxLhFbiiuDXlUd0rVQ3 yDPkMri6laq4oO58uEh+uc6ckdZywTeF8MtGWGZPUg4DPFPSxng/01ZnleIE0y7l +4obRbSMXQo0uS+Wnvh5ffy4U8UCB3h2M2LYFAy1dQG1l9aPDd+HtGXGThqI+Vel 0CdWsP+l3DOgXAeKUfv24GzOvEDiArkWGSXy74xcCHMiSfd7OZXbwFA+4tcoufDd S8eoP5+cQdfCXmbHPtoOK+QMbSxtShmbkG1DIZqmksufRo4g6glNXz/W0O4wkNua Cet2a0qagIEyV5PElsbhY5PZSdARsDSd0NgUFDZDCKdII1RQOXqRduazsIEU70zZ mVDYQt3JVGa7Qn/kThX3NWIln4T6hq4H9WbQn03BYbz84ovAk8Fdioy6YXnNAfWS jeOmMqjI3g4pM/ejT7ArVV0K/wt/r9Z+6pQYgvU3DrASZvisKYXfkWphPkpxSG2q RkAxr1b1n6LLmiA+AFpFXVq9gYm+6zWPwThCNOOQFBU6EGCDMqwZa9nKRUc5QXDC 0891TXBI3WQIFp4ast5svdVrkxX/rt2fhJJ8GSudBDvet3VOF1XrXUvLIq4LDqL5 GaQumWe4Jjd4/p4iShPN5byYVN5TjhA4s0MfZHWwLCyMZaam8Lo= =flfS -----END PGP SIGNATURE-----