#-*-Coding:utf-8-*-#to find where to use the "table on xxxxx xxxxxx production env '" In the project our metadata management is not very good, if you know where a table has been used before,
You need to write a program to traverse the "Import os import os.path RootDir =" C:\\users\\ibm_admin\\ibm\\rationalsdp\\workspace "# to indicate the folder being traversed query = "XXXXXXXXX" def Walk_all_files (rootdir,query): for parent,dirnames,filenames in OS Walk (RootDir): #for循环自动完成递归枚举 #三个参数: return 1. Parent directory (current path) 2. All folder names (excluding paths) 3. All file names for dirname in Dirnames:
#输出文件夹信息 #print "Parent is:" + parent #print "DirName is:" + dirname
Pass to filename in filenames: #输出文件信息 #print ' parent is: ' + Parent
#print ' filename is: ' + filename #print ' The full name of the ' file is: ' + os.path.join (parent,filename) Is_file_contain_word (Os.path.join (parent,filename), query) def is_file_contain_word (File_,query_word): #print 1111111 if Query_woRd in Open (File_). Read (): print File_ filecontext = open (File_). Read () lines = Filecontext.split ( ' \ n ') # python print keywords in row for line in Lines:if Query_word in Line:print Line Walk_all_files (rootdir,query) print "Do" http://www.iplaypy.com/jichu/note.html please explain Os.walk () : The Walk () method syntax format is as follows: Os.walk (top[, topdown=true[, onerror=none[, Followlinks=false]]) os.walk (top[, topdown=true[, onerror=none[, Followlinks=false]]) parameter top-each folder (including itself) under the root directory, resulting in a 3-tuple (Dirpath, Dirnames, filenames) folder path, folder name,
File name ". Topdown-optional, true or unspecified, the 3-tuple of a directory will be generated first (from top to bottom) in the 3-tuple of any of its subfolders.
If Topdown is False, a 3-tuple of a directory will be generated after the 3-tuple of any of its subfolders (the directory is bottom-up). OnError--optional, is a function; It is called with a parameter, a OSError instance.
After reporting this error, continue walk, or throw exception terminate walk.
Followlinks--set to True, the directory is accessed through a soft link.
Return value the method has no return value. '''