我有一個python腳本試圖將兩個文件相互比較並輸出差異。但我不知道究竟是怎麼回事,當我運行它給我一個錯誤的腳本如何通過python中的目錄進行掃描?
NotADirectoryError: [WinError 267] The directory name is invalid: 'C:\\api\\API_TEST\\Apis.os\\*.*'
,因爲我不知道爲什麼它是追加*。 *在文件擴展結束時。
這是目前我的功能:
def CheckFilesLatest(self, previous_path, latest_path):
for filename in os.listdir(latest_path):
previous_filename = os.path.join(previous_path, filename)
latest_filename = os.path.join(latest_path, filename)
if self.IsValidOspace(latest_filename):
for os_filename in os.listdir(latest_filename):
name, ext = os.path.splitext(os_filename)
if ext == ".os":
previous_os_filename = os.path.join(previous_filename, os_filename)
latest_os_filename = os.path.join(latest_filename, os_filename)
if os.path.isfile(latest_os_filename) == True:
# If the file exists in both directories, check if the files are different; otherwise mark the contents of the latest file as added.
if os.path.isfile(previous_os_filename) == True:
self.GetFeaturesModified(previous_os_filename, latest_os_filename)
else:
self.GetFeaturesAdded(latest_os_filename)
else:
if os.path.isdir(latest_filename):
self.CheckFilesLatest(previous_filename, latest_filename)
爲什麼它不能掃描目錄,並尋找適合例如OS文件有什麼想法?
它失敗在線:
for os_filename in os.listdir(latest_filename):
代碼首先會從
def main():
for i in range(6, arg_length, 2):
component = sys.argv[i]
package = sys.argv[i+1]
previous_source_dir = os.path.join(previous_path, component, package)
latest_source_dir = os.path.join(latest_path, component, package)
x.CheckFilesLatest(previous_source_dir, latest_source_dir)
x.CheckFilesPrevious(previous_source_dir, latest_source_dir)
稱爲謝謝
如果你告訴我們在什麼情況下引發異常,這將有所幫助。 –
對不起,它的失敗說明:對於os.listdir(latest_filename)中的os_filename: – user974873
你能檢查這個函數的argumetns是什麼。在函數入口點添加打印語句 –