# Errors reading DICOM files

**URL:** <https://discourse.itk.org/t/errors-reading-dicom-files/5016>\
**Category:** Beginner Questions\
**Tags:** dicom, simpleitk\
**Created:** [May 27, 2022, 4:44pm UTC](https://discourse.itk.org/t/errors-reading-dicom-files/5016 "2022-05-27T16:44:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)\
**Post date:** [May 27, 2022, 4:44pm UTC](https://discourse.itk.org/t/errors-reading-dicom-files/5016/1 "2022-05-27T16:44:22Z")

</div>

Hello,  
I am new to python and ITK.  
I want to read a series of Dicom images. For this, I copied the below code snippet from a previous query.

```auto
import SimpleITK as sitk

# A file name that belongs to the series we want to read
file_name = '1.dcm'
data_directory = 'CIRS057A_MR_CT_DICOM'

# Read the file's meta-information without reading bulk pixel data
file_reader = sitk.ImageFileReader()
file_reader.SetFileName(file_name)
file_reader.ReadImageInformation()

# Get the sorted file names, opens all files in the directory and reads the meta-information
# without reading the bulk pixel data
series_ID = file_reader.GetMetaData('0020|000e')
sorted_file_names = sitk.ImageSeriesReader.GetGDCMSeriesFileNames(data_directory, series_ID)

# Read the bulk pixel data
img = sitk.ReadImage(sorted_file_names)

```

I am getting the following error

```auto
RuntimeError: Exception thrown in SimpleITK ImageFileReader_ReadImageInformation: C:\Miniconda\envs\bld\conda-bld\work\Code\IO\src\sitkImageReaderBase.cxx:97:
sitk::ERROR: The file "1.dcm" does not exist.

```

Please explain to me what is happening and how to solve this.

---

<div class="post-metadata">

**Author:** ![zivy](https://discourse.itk.org/user_avatar/discourse.itk.org/zivy/32/1726_2.png) [@zivy](https://discourse.itk.org/u/zivy)\
**Post date:** [May 27, 2022, 5:07pm UTC](https://discourse.itk.org/t/errors-reading-dicom-files/5016/2 "2022-05-27T17:07:43Z")

</div>

Hello @debapriya,

As the error says, a file named `1.dcm` cannot be found in the directory in which the code is run. Likely this is because the file is in the `data_dirctory` and this line:

```auto
file_reader.SetFileName(file_name)

```

should be:

```auto
file_reader.SetFileName(os.path.join(data_directory,file_name))

```

For future reference, when posting code on discourse, please use backticks to format it, as [described here](https://meta.discourse.org/t/how-to-post-code-or-preformatted-text/188910). This makes it much more readable and easier to understand.

---

<div class="post-metadata">

**Author:** ![debapriya](https://discourse.itk.org/letter_avatar_proxy/v4/letter/d/bc79bd/32.png) [@debapriya](https://discourse.itk.org/u/debapriya)\
**Post date:** [May 28, 2022, 5:58am UTC](https://discourse.itk.org/t/errors-reading-dicom-files/5016/3 "2022-05-28T05:58:16Z")

</div>

It worked !! Thank you !

```nohighlight
For future reference, when posting code on discourse, please use backticks to format it, as [described here](https://meta.discourse.org/t/how-to-post-code-or-preformatted-text/188910). This makes it much more readable and easier to understand.

```

Sure !
