glob() 中的多个数组
Multiple array in glob()
我有以下代码工作正常但在使用文件夹通配符时速度很慢,因为它解析的文件夹很多。我需要将其限制为我想提供的列表以限制其搜索;
如何将此文件夹列表(例如 folder=['A,B,C'] )解析为 glob,以便将其搜索限制为仅对这些文件夹进行搜索,而不是使用 * 通配符。由于文件夹数量众多,这将使它的工作速度更快。
tra=['70XX','81YY']
TargetFolder = r'C:\ELK\LOGS\ATH\DEST'
all_files = []
for directory in tra:
files = glob.glob('Z:/{}/*/asts_data_logger/*.bz2'.format(directory))
for f in files:
current_path = Path(f)
if current_path.name in filenames_i_want:
print(f"found target file: {f}")
shutil.copy2(f, TargetFolder)
遍历文件夹列表并将它们替换为路径名,就像您对 tra
中的目录所做的那样。
import itertools
folders=['A', 'B', 'C']
tra=['70XX','81YY']
TargetFolder = r'C:\ELK\LOGS\ATH\DEST'
all_files = []
for directory, folder in itertools.product(tra, folders):
files = glob.glob('Z:/{}/{}/asts_data_logger/*.bz2'.format(directory, folder))
for f in files:
current_path = Path(f)
if current_path.name in filenames_i_want:
print(f"found target file: {f}")
shutil.copy2(f, TargetFolder)
我有以下代码工作正常但在使用文件夹通配符时速度很慢,因为它解析的文件夹很多。我需要将其限制为我想提供的列表以限制其搜索;
如何将此文件夹列表(例如 folder=['A,B,C'] )解析为 glob,以便将其搜索限制为仅对这些文件夹进行搜索,而不是使用 * 通配符。由于文件夹数量众多,这将使它的工作速度更快。
tra=['70XX','81YY']
TargetFolder = r'C:\ELK\LOGS\ATH\DEST'
all_files = []
for directory in tra:
files = glob.glob('Z:/{}/*/asts_data_logger/*.bz2'.format(directory))
for f in files:
current_path = Path(f)
if current_path.name in filenames_i_want:
print(f"found target file: {f}")
shutil.copy2(f, TargetFolder)
遍历文件夹列表并将它们替换为路径名,就像您对 tra
中的目录所做的那样。
import itertools
folders=['A', 'B', 'C']
tra=['70XX','81YY']
TargetFolder = r'C:\ELK\LOGS\ATH\DEST'
all_files = []
for directory, folder in itertools.product(tra, folders):
files = glob.glob('Z:/{}/{}/asts_data_logger/*.bz2'.format(directory, folder))
for f in files:
current_path = Path(f)
if current_path.name in filenames_i_want:
print(f"found target file: {f}")
shutil.copy2(f, TargetFolder)