Python Forum

Full Version: Dicom Files
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,
I am using the following code to read one dicom file and write the info from that file to a text file.

ds=dicom.dcmread("mw_test.dcm")
file=open("mw_test.txt","w+")
file.write(str(ds))
file.close()
How can I expand this code for reading multiple dicom files from a directory and write the contents in a text fie with the same file name?
using files like that is potentially dangerous
because if an Exception happened before you close the file (like an user killing the process)
it could break the entire file.
for max security use the "with" statement
Have a look at listdir