Files
python:在選定的路徑上應用 glob
最近我已經切換到 python,現在專注於了解如何將它應用於以類似的方式處理填充,就像我使用 bash 所做的那樣:
# obtain path where we are mow pwd = os.getcwd() print("This is a directory with the script: %s" % pwd) # join folder with the filles to be analysed to PWD data = os.path.join(pwd,"data") print("This is a directory with the data %s" % data)
現在我如何應用 glob 載入副檔名為 DLG 的 DATA 中的所有填充?像這樣的東西不起作用
dirlist = glob.glob(data/"*.dlg")
您可以將目前工作目錄更改為data然後執行glob:
#!/bin/python import os import glob # obtain path where we are mow pwd = os.getcwd() print("This is a directory with the script: %s" % pwd) # join folder with the filles to be analysed to PWD data = os.path.join(pwd,"data") print("This is a directory with the data %s" % data) os.chdir(data) files_grabbed = [glob.glob('*.dlg')] print files_grabbed