【发布时间】:2014-12-01 08:04:03
【问题描述】:
我正在尝试读取文件夹树中的一系列 DICOM 文件,并且我正在使用以下代码在树中运行,同时读取每个文件。问题是我得到了肯定存在的文件的 IOErrors,我已经检查了文件权限和其他 SO 线程,例如Python: IOError: [Errno 2] No such file or directory,但是如果没有这些 IOErrors,我还没有设法让它工作。有人有什么想法吗?
for root, dirs, files in os.walk(path):
for fname in files:
name = os.path.basename(os.path.abspath(fname))
if name.startswith('.') == True:
pass
else:
try:
plan=dicom.read_file(fname)
ds=dicom.read_file(fname, stop_before_pixels = True)
kVp = TagChecker([0x18,0x60]) #KVP
Target = TagChecker([0x18,0x1191]) #ANODE
Filter = TagChecker([0x18,0x7050]) #
write_results.writerow([Survey_Number, Patient_ID, View_Protocol, int(kVp), Target, Filter, Thickness, mAs_Exposure, LPad_Yes_No, autoorman, AECMode, AECDset, Patient_Age, Comment, Compression_Force])
#print(fname)
except IOError:
print "IOError: ", "//" + os.path.join(root, fname) + "//"
except InvalidDicomError:
# This exception line prints an error message to the command line, checks to see if an error log
# has been generated for this session, writes a new one if not and then writes the error to the log file
print "Invalid Dicom File: ", fname
【问题讨论】:
-
我已经把它缩小到我在文件夹中循环编码的方式上美好的。有人可以帮忙吗?