試圖讓我的腳本的一部分起作用。該部分將讓用戶定義Web根目錄,以便我們可以在該目錄中搜索惡意軟件。這是我正在研究的部分:我需要能夠獲得用戶輸入并將其添加為搜索功能的變量。我敢肯定我會把這一切弄錯了。import osfor root in raw_input("Where is the web root? "): if os.path.isdir(root): print "Using %r" % (root) elif os.path.isdir(root): print "Directory not found."我想讓腳本檢查目錄以確保它存在(如果輸入錯誤),然后繼續并運行對某些字符串的搜索。謝謝!
1 回答

人到中年有點甜
TA貢獻1895條經驗 獲得超7個贊
我想你需要在while這里循環:
import os
root = raw_input("Where is the web root? "
while not os.path.isdir(root):
print "Directory not found, try again"
root = raw_input("Where is the web root? ")
print "Using %r" % (root)
#or do something else with root here
添加回答
舉報
0/150
提交
取消