1Answers
How to implement in Python: find the txt document with the same content as the speech recognition, and output the path where the txt file is located
Asked by: Ward 187 views IT
How to implement in Python: find the txt document with the same content as the speech recognition, and output the path where the txt file is located
+4Votes
Import os def os_walker(folder): """Trouble through the files in the foler""" path = os .path.abspath(folder) for root,dirs,files in os.walk(path): if Dirs: continue #print root,dirs,files for f in files: yield f , os.path.abspath(os.path.join(root,f)) def compare(f1, f2): """"Comparative The files in both folders """" f1_list = {f:p for f,p in os_walker(f1)} f2_list = {f:p for f ,p in os_walker(f2)} common = {_:f1_list[_] for _ in f1_list if _ in f2_list} print "common: ", common f1_specific = {_:f1_list[_] for _ in f1_list if _ not in f2_list} print "f1_specific", f1_specific f2_specific = {_:f2_list[_] for _ in f2_list if _ not in f1_list} print "f2_specific", f2_specific
compare("FOLDER1","FOLDER2")
The code has a lot of limitations, such as not considering subdirectories, etc. The core idea is to use os.walk.