最近我已经切换到 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 来加载 DATA 内扩展名为 DLG 的所有填充?像这样的东西是行不通的
dirlist = glob.glob(data/"*.dlg")
答案1
您可以更改当前工作目录到数据然后执行全局:
#!/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