dicomdir
Writes the DICOMDIR that indexes the DICOM files under a directory, or lists the records of an existing one.
When to use it
Use dicomdir to prepare a directory for media (a CD, DVD or USB stick a
viewer reads with PS3.10 media rules), or to see what a DICOMDIR you were
given holds. It writes one record for each patient, study, series and
instance, and for an instance that is not an image the record type of its
SOP class (an SR document, for example).
A DICOMDIR names files by File IDs, which PS3.10 8.5 limits to at most eight
components of at most eight characters from A-Z, 0-9 and _, with no
extension. Most directories do not keep to that (ct.dcm), so the command
refuses them by name and never renames a file. --copy-to copies the files
into a new directory under names that keep to the rule and writes the
DICOMDIR there.
The closest tools are dcmtk's dcmmkdir and pydicom's FileSet.
Examples
A directory whose names will not do
go-dicom dicomdir export/Error: dicomdir: 3 file(s) are not named as a File ID must be (PS3.10 8.5: components of at most 8 characters from A-Z, 0-9 and _, no extension), so a DICOMDIR could not index them for media; nothing was written. Rename them, or copy them under names that do with --copy-to <new directory>:
ct.dcm
mr.dcm
report.dcmCopy the files under File IDs and index them
go-dicom dicomdir --copy-to media/ export/Wrote media/DICOMDIR: 3 patient, 3 study, 3 series, 2 image, 1 sr documentThe files go to media/DICOM/IM000001, IM000002 and so on, in the order
of their paths; the originals are left as they were. The target must not
exist or must be empty.
A directory already named for media
go-dicom dicomdir named/skipped named/README (not a DICOM instance)
Wrote named/DICOMDIR: 1 patient, 1 study, 1 series, 1 imageSubdirectories are walked. Files that are not DICOM are left out and named on standard error.
List a DICOMDIR
go-dicom dicomdir --list media/DICOMDIRDICOMDIR media/DICOMDIR
PATIENT PatientName=CompressedSamples^CT1 PatientID=1CT1
STUDY StudyDate=20040119 StudyID=1CT1 StudyInstanceUID=1.3.6.1.4.1.5962.1.2.1.20040119072730.12322
SERIES Modality=CT SeriesNumber=1 SeriesInstanceUID=1.3.6.1.4.1.5962.1.3.1.1.20040119072730.12322
IMAGE DICOM/IM000001 InstanceNumber=1 ReferencedSOPInstanceUIDInFile=1.3.6.1.4.1.5962.1.1.1.1.1.20040119072730.12322
…
3 patient, 3 study, 3 series, 2 image, 1 sr document--list takes the DICOMDIR or the directory it sits in. Add --json for the
records as JSON with "schemaVersion": 1, their counts and each record's
attributes.
Replace one, with a label
go-dicom dicomdir --force --file-set-id STUDY_2026 media/Wrote media/DICOMDIR: 3 patient, 3 study, 3 series, 2 image, 1 sr documentAn existing DICOMDIR is replaced only with --force
(Error: dicomdir: media/DICOMDIR already exists; --force replaces it), and
is never indexed itself. --file-set-id sets the File-set ID, the label of
the media, at most 16 characters.
Notes
- Nothing is written when any file breaks the File ID rule: the command lists every such file and exits 1.
- The DICOMDIR is written at the root of the directory it indexes (or of the
--copy-todirectory). Exit status is 0 on success, 1 on any error. - To de-identify files for media, run anonymize first, then
dicomdiron its output: anonymize does not write a DICOMDIR. - See CONFORMANCE.md, Media, Key Object Selection and video.
See also
Options
COMMAND: dicomdir - Write the DICOMDIR of a directory, or list one
USAGE:
go-dicom dicomdir <directory> [options]
go-dicom dicomdir --list <DICOMDIR or directory> [--json]
DESCRIPTION:
Without --list, index the DICOM files under <directory>, and the
directories below it, in a DICOMDIR written at its root (PS3.3 Annex F,
PS3.10): one record for each patient, study, series and instance, and for
an instance that is not an image the record type of its SOP class. Files
that are not DICOM are left out and named on standard error.
With --list, print the records of an existing DICOMDIR as a tree, or as
JSON with "schemaVersion" 1.
File IDs. A DICOMDIR names the files it indexes by File IDs, and PS3.10
8.5 allows at most eight components of at most eight characters from A-Z,
0-9 and underscore: no lower case, no extension. Most directories do not
keep to it (ct.dcm, IMG0001.DCM), and an index of names a reader of the
media cannot follow is wrong. So the command refuses by name: it lists
every file whose name breaks the rule and writes nothing. It never
renames a file. To index files as they are on a medium, --copy-to copies
them into a new directory as DICOM/IM000001, DICOM/IM000002 and so on,
in the order of their paths, and writes the DICOMDIR there; the originals
are left as they were.
A DICOMDIR already in the directory is replaced only with --force, and is
not itself indexed.
OPTIONS:
-h, --help Show help for this command
--list List an existing DICOMDIR
--json With --list, print the records as JSON
--copy-to <dir> Copy the files into <dir>, which must not exist or
be empty, under File IDs PS3.10 allows, and write
the DICOMDIR there
--force Replace a DICOMDIR that is already there
--file-set-id <id> The File-set ID, the label of the media (at most
16 characters)
EXAMPLES:
go-dicom dicomdir study/
go-dicom dicomdir --copy-to media/ export/
go-dicom dicomdir --list study/DICOMDIR
go-dicom dicomdir --list --json study/
go-dicom dicomdir -hdiff
Compares two DICOM files element by element, into sequences and items, and prints what one file has that the other lacks and what both have with a different VR or value. It prints nothing when the files are equal.
sr
Prints a Structured Report (PS3.3 C.17) as the document it is: a header, then its content items as an indented tree, one item to a line.