# Did ITK can read a directory of one serial that of many files, and write into one dcm file of multi frames.

**URL:** <https://discourse.itk.org/t/did-itk-can-read-a-directory-of-one-serial-that-of-many-files-and-write-into-one-dcm-file-of-multi-frames/5213>\
**Category:** Beginner Questions\
**Tags:** dicom\
**Created:** [July 25, 2022, 2:47am UTC](https://discourse.itk.org/t/did-itk-can-read-a-directory-of-one-serial-that-of-many-files-and-write-into-one-dcm-file-of-multi-frames/5213 "2022-07-25T02:47:47Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wulicheng](https://discourse.itk.org/user_avatar/discourse.itk.org/wulicheng/32/1390_2.png) [@wulicheng](https://discourse.itk.org/u/wulicheng)\
**Post date:** [July 25, 2022, 2:47am UTC](https://discourse.itk.org/t/did-itk-can-read-a-directory-of-one-serial-that-of-many-files-and-write-into-one-dcm-file-of-multi-frames/5213/1 "2022-07-25T02:47:47Z")

</div>

Now I have a CT serial in a directory, now I want to read all the serial files and write it into one single dcm file.

---

<div class="post-metadata">

**Author:** ![dzenanz](https://discourse.itk.org/user_avatar/discourse.itk.org/dzenanz/32/1093_2.png) [@dzenanz](https://discourse.itk.org/u/dzenanz)\
**Post date:** [July 25, 2022, 1:44pm UTC](https://discourse.itk.org/t/did-itk-can-read-a-directory-of-one-serial-that-of-many-files-and-write-into-one-dcm-file-of-multi-frames/5213/2 "2022-07-25T13:44:08Z")

</div>

You can write it into a one `.dcm` file. Example:

```cpp
#include "itkImageFileWriter.h"
#include "itkRandomImageSource.h"

int
main()
{
  using ImageType = itk::Image<unsigned short, 3>;
  using RS = itk::RandomImageSource<ImageType>;
  RS::Pointer rs = RS::New();
  rs->Update();
  itk::WriteImage(rs->GetOutput(), "C:/a/testOut.dcm");

  return 1;
}

```

produces this file:  
[testOut.dcm](https://discourse.itk.org/uploads/short-url/mphKkvSBOD549lUuse6XG6XtbTz.dcm) (517 KB)

If you want to carry over metadata from the source series, you might need something like:

```cpp
image->SetMetaDataDictionary(inputImage->GetMetaDataDictionary());
itk::WriteImage(image, "C:/a/testOut.dcm");

```

You should also take a look at [Dicom ChangeHeader](https://github.com/InsightSoftwareConsortium/ITK/blob/master/Examples/IO/DicomImageReadChangeHeaderWrite.cxx) example.

---

<div class="post-metadata">

**Author:** ![wulicheng](https://discourse.itk.org/user_avatar/discourse.itk.org/wulicheng/32/1390_2.png) [@wulicheng](https://discourse.itk.org/u/wulicheng)\
**Post date:** [July 29, 2022, 11:16pm UTC](https://discourse.itk.org/t/did-itk-can-read-a-directory-of-one-serial-that-of-many-files-and-write-into-one-dcm-file-of-multi-frames/5213/3 "2022-07-29T23:16:48Z")

</div>

Thank you very much! I got it.
