angela 发表于 2018-8-15 07:55:24

如何用python写一个简单的find命令

def find(dir,word,type='f',use_like=False):  
    res=os.walk(dir)
  
    for tree_list in res:
  
      if type == "f":
  
            mt=2
  
      elif type == "d":
  
            mt=1
  
      else:
  
            print "This type %s is noexist" % type
  
      for name in tree_list:
  
            if use_like == False:
  
                if word == name:
  
                  print "{path}/{name}".format(path=tree_list,name=name)
  
            else:
  
                if word in name:
  
                  print "{path}/{name}".format(path=tree_list,name=name)
  
find('/usr','ls')
页: [1]
查看完整版本: 如何用python写一个简单的find命令