【发布时间】:2021-04-20 17:18:35
【问题描述】:
我有一个关于 glob 和文件路径的问题 - 假设我有一个静态文件路径,格式为
G:\ML_CDetector_ImageArchive\BreastCancer\RawFolder\Duke-Breast-Cancer-MRI\Duke-Breast-Cancer-MRI
我想在之后为文件夹添加变量路径,因为每个患者的文件夹命名约定不同 - 而患者文件夹约定是标准的,例如:
Breast_MRI_XXX - 其中 x 是 1-922 之间的数字(通过使用 while 循环我已经能够处理),最后内部文件夹是它变得有点时髦的地方,但我又一次没有去过能够通过以下通配符运算符的使用通过 glob 处理此问题:
f"{currentPatient}\\*\\ 现在在文件夹中还有几个我想输入的文件夹,以便名称部分匹配:
gl.glob(f"{currentPatient}\\*\\[3rd]*\\*.dcm") 但令我沮丧的是,我无法像以前那样获得正确的文件夹
for item in globInnerFolder:
print(item)
我返回了一个空的打印形式:
[]
[]
[]
[]
[]
[]
[]
[]
[]
[]
什么都没有显示,也没有错误 - 我将如何执行以下操作 - 快速说明我已经尝试使用 glob 和 iglob 来查看是否有任何返回和 nada:
fpMainFolder = gl.glob("G:\\ML_CDetector_ImageArchive\\BreastCancer\\RawFolder\\Duke-Breast-Cancer-MRI\\Duke-Breast-Cancer-MRI\\")
# Loop Variable
j = 0
# while (j < len(csvList)):
while (j < 10):
# Image Configuration
currentPatient = str(csvList[j][0])
# yStartPixel = int(csvList[j][1])
# yEndPixel = int(csvList[j][2])
# xStartPixel = int(csvList[j][3])
# xEndPixel = int(csvList[j][4])
# sliceStart = int(csvList[j][5])
# sliceEnd = int(csvList[j][6])
#imageSize = (yEndPixel - yStartPixel), (xEndPixel - xStartPixel)
# Patient Folder Loop Variable
try:
globInnerFolder = gl.glob(f"{currentPatient}\\*\\[3rd]*\\*.dcm")
print(globInnerFolder)
for item in globInnerFolder:
print(item)
except:
try:
globInnerFolder = gl.iglob(f"{currentPatient}\\*\\[ph3ax]*\\*.dcm")
for item in globInnerFolder:
print(item)
except:
print("Exiting - No File Structure Found")
exit()
这是一个完整文件路径的示例
G:\ML_CDetector_ImageArchive\BreastCancer\RawFolder\Duke-Breast-Cancer-MRI\Duke-Breast-Cancer-MRI\Breast_MRI_001\01-01-1990-MRI BREAST BILATERAL WWO-97538\3.000000-ax dyn pre-93877
【问题讨论】:
标签: python python-3.x glob