bug-findutils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The quickest way to not to descend into sub-directories once a file


From: Stephane Chazelas
Subject: Re: The quickest way to not to descend into sub-directories once a file is found?
Date: Wed, 2 Oct 2019 23:25:58 +0100
User-agent: NeoMutt/20171215

2019-10-02 17:10:25 -0500, Peng Yu:
> I’ve checked this many years ago. One directory exec is not acceptable in
> my case. I ended up with two pass, one to check which directory to include
> and exclude, then search for files in the directory included. But I am
> looking for something better.
[...]

Try

python -c '
import os
for root, dirs, files in os.walk("."):
  if "file.txt" in files:
    dirs[:]=[]
    print(os.path.join(root, "file.txt"))'

(note that it doesn't check that "file.txt" is a *regular* file,
only that it's not a directory (it may still be a symlink to a
directory); while that could be added, I don't expect you would
care much about it).

-- 
Stephane




reply via email to

[Prev in Thread] Current Thread [Next in Thread]