I am trying to find the first result of a file found in a root directory without using a for loop.
Is that possible? I tried using rglob and os.walk() but I still end up needing a for loop to get to my result which wastes time as I only need the first result I get.
i used this post to try and use it with rglob but unfortunately it did not work for me:
fp = r"C:\Users\AnxPi\Desktop\test_DS"
fp_pickle = Path(fp).rglob('*test.pkl')
print(fp_pickle)
Output:
<generator object Path.rglob at 0x0000023957C84CF0>
It only works if I do the following, which is the same as running a for loop:
sorted(Path(fp).rglob(*test.pkl'))[0]