我有了幾行文本文件,讓說:如何檢查,看看是否在內容文件存在於目錄中的文件中的內容
cat
dog
rabbit
我想遍歷目錄來檢查是否有任何文本文件包含上述列表中的項目。
我嘗試了許多不同的方法。我不想發佈任何內容,因爲我想要一個新的開始......思路清晰。我對下面的代碼進行了處理,以至於我甚至不知道發生了什麼,並且我完全失去了意義。 :(
#! /usr/bin/python
'''
The purpose of this program
is to search the OS file system
in order to find a txt file that contain the nagios host entries
'''
import os
host_list = open('/path/path/list', 'r')
host = host_list.read()
##for host in host_remove.read():
host_list.close()
#print host
for root, dirs, files in os.walk("/path/path/somefolder/"):
for file in files:
if file.endswith(".txt"):
check_file = os.path.join(root, file)
#print check_file
if host.find(check_file): #in check_file:
print host.find(check_file)
#print host+" is found in "+check_file
#print os.path.join(root, file)
else:
break
你的問題的第二部分完全是題外話。我刪除它。 – MattDMo 2014-08-28 17:52:34
您可以分享您迄今爲止的嘗試嗎? – dano 2014-08-28 18:46:41
第二個問題是公平的嗎?但任何誰 – user3655020 2014-08-28 18:51:20