Re: Searching for a file

2025-05-27 Thread Peter J. Holzer
On 2025-05-24 17:18:11 -0600, Mats Wichmann wrote: > On 5/23/25 16:05, Rob Cliffe via Python-list wrote: > > On 23/05/2025 18:55, Mats Wichmann wrote: > > > On 5/22/25 21:04, Rob Cliffe via Python-list wrote: > > > > It occurs to me that it might be useful if Python provided a > > > > function to s

Re: Searching for a file

2025-05-27 Thread Roland Mueller via Python-list
When answering I saw only the post from Peter. Everything else was in SPAM folder. GMail was so kind to move the "junk" mails to my Inbox after pressing SENT :-) My code works in Linux but with a small change it should work in Windows too. ti 27.5.2025 klo 17.41 Roland Mueller (roland.em0...@goog

Re: Searching for a file

2025-05-27 Thread Roland Mueller via Python-list
To get a list of files in a given directory one can use glob.glob and os.path.isfile >>> from os.path import isfile >>> from glob import glob >>> files_in_var_tmp = [f for f in glob('/var/tmp/*') if isfile(f) ] For several directories iterate over the dirs and add the resulting list of files. >>

Re: Searching for a file

2025-05-24 Thread Chris Angelico via Python-list
On Sun, 25 May 2025 at 10:05, Rob Cliffe via Python-list wrote: > Yes, but if I understand correctly, they all start from a single > directory (and work downwards if required). > My suggestion involved searching a *list* (possibly multiple lists) of > directories. for dir in dirs: try: open(d

Re: Searching for a file

2025-05-24 Thread Rob Cliffe via Python-list
On 25/05/2025 00:18, Mats Wichmann wrote: On 5/23/25 16:05, Rob Cliffe via Python-list wrote: On 23/05/2025 18:55, Mats Wichmann wrote: On 5/22/25 21:04, Rob Cliffe via Python-list wrote: It occurs to me that it might be useful if Python provided a function to search for a file with a give

Re: Searching for a file

2025-05-24 Thread Mats Wichmann
On 5/23/25 16:05, Rob Cliffe via Python-list wrote: On 23/05/2025 18:55, Mats Wichmann wrote: On 5/22/25 21:04, Rob Cliffe via Python-list wrote: It occurs to me that it might be useful if Python provided a function to search for a file with a given name in various directories (much as the i

Re: Searching for a file

2025-05-23 Thread Rob Cliffe via Python-list
On 23/05/2025 18:55, Mats Wichmann wrote: On 5/22/25 21:04, Rob Cliffe via Python-list wrote: It occurs to me that it might be useful if Python provided a function to search for a file with a given name in various directories (much as the import.import_lib function searches for a module in th

Re: Searching for a file

2025-05-23 Thread Mats Wichmann
On 5/22/25 21:04, Rob Cliffe via Python-list wrote: It occurs to me that it might be useful if Python provided a function to search for a file with a given name in various directories (much as the import.import_lib function searches for a module in the directories in sys.path). This function w

Searching for a file

2025-05-22 Thread Rob Cliffe via Python-list
It occurs to me that it might be useful if Python provided a function to search for a file with a given name in various directories (much as the import.import_lib function searches for a module in the directories in sys.path). This function would perhaps be best placed in the os.path or os modu