0

I am attempting to create a python desktop assistant, on of the roles is to print out any files matching the user's input. This works, but does not extract from folders within the parent directory.

def run():
p("Please enter file name\n")
a = input('> ')
import glob, os
os.chdir("H:/")
for file in glob.glob(a+'.*'):
    print(file)
Luke S
  • 3
  • 3
  • 1
    your pattern includes an extension (because of the '.*'), so it would ignore directories. Do you mean that you want the search to be recursive inside folders and subfolders? – zoubida13 May 20 '16 at 11:14
  • you could use this answer: http://stackoverflow.com/questions/3964681/find-all-files-in-directory-with-extension-txt-in-python – user2469085 May 20 '16 at 11:17
  • That's how I got the orginal code, but it wasn't searching in any sub folders – Luke S May 20 '16 at 11:59

1 Answers1

0

Supposing you want to print all files that contain an input string:

def run():
    match_this = raw_input('Please enter string to match > ')

    for dirpath, _, filenames in os.walk('H:\\'):
        for filename in filenames:
            if match_this in filename:
                print os.path.join(dirpath, filename)
adrian.nicolau
  • 516
  • 7
  • 17