3

I'm quite a newbie when it comes to Python so excuse me if this is a very simple thing.

How do I make a program search for a file through the whole computer and add the directory of the file to a string?

For example, I want to search for example.py even though I don't have any idea where it could be located.

PS: I'm using Python 3.6.2 in case you need to know that.

Thanks for the help!

pkisztelinski
  • 522
  • 3
  • 14
Mike
  • 31
  • 1
  • What have you tried and where are you failing? You may want to look at [`os.walk`](https://docs.python.org/3.6/library/os.html?highlight=walk#os.walk). – AChampion Jul 30 '17 at 15:20
  • `os.walk('/')`. – cs95 Jul 30 '17 at 15:21
  • @cᴏʟᴅsᴘᴇᴇᴅ I haven't really tried anything considering I barely know how to use Python. I've seen `os.walk` used in some examples but I can't really understand how to use it. – Mike Jul 30 '17 at 15:25
  • 1
    @Mike I've marked your answer a duplicate of an existing problem that should fit your needs. Hope it helps. – cs95 Jul 30 '17 at 15:27
  • or from the `cli` do `grep -r "your_text_here"` although be warned it can be slow – gold_cy Jul 30 '17 at 15:27
  • @cᴏʟᴅsᴘᴇᴇᴅ Thanks, I'll look into it. – Mike Jul 30 '17 at 15:29

0 Answers0