File searching in python -


i want function takes string argument (data) , breaks string words (word). afterwards, should take files in directory, each file name , check if words present in file name or not. if present print name of file , print "do want open " if yes print "opened" , break loops. if no should continue searching.

at end, should print whether file present or not in directory.

here's code wrote.

def file_search(data):   data = data.split()    root, dirs, files in os.walk("/media/", topdown=false):        word_match = true        opened = false         if not opened:              name in files:                 word in data:                     if word not in name:                         word_match = false                  if word_match:                     print "file found:" + name + "where path is" + root                     print "do want open "                     answer = raw_input()                     if answer == "yes" :                         opened = true                         print "file opened"                         break 

somehow fixed it.

def file_search2(name, name_words): check = true word in name_words:     if word not in name:         check = false         break  return check     def file_search(filename):     file_found = false     file_opened = false     words = filename.split()      root, dirs, files in os.walk('/media/', topdown=false):          name in files:                if file_search2(name, words) , file_opened == false:                 file_found = true                 print "file found :" + name                 print "do want open file:"                 answer = raw_input()                 if "yes" in answer:                     file_opened = true                     print "file opened successfully"      if file_opened == false:         print "file not found"    file_search("file name space") 

Comments

Popular posts from this blog

networking - Vagrant-provisioned VirtualBox VM is not reachable from Ubuntu host -

c# - ASP.NET Core - There is already an object named 'AspNetRoles' in the database -

ruby on rails - ArgumentError: Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true -