Converting one subject by hand is pleasant. Converting a hundred subjects by hand is a punishment. The moment your study grows past a handful of sessions, you need batch conversion: a repeatable, scripted way to run dcm2niix over whole studies at once. This guide shows you how to organize your folders, write a simple loop, check the results in bulk, and avoid the traps that turn big batches into big messes. The goal is a workflow you can run, rerun, and hand to a colleague without a long explanation.
Organize folders before you automate
Batch conversion rewards tidy folders and punishes messy ones. Before you write any script, settle a layout and stick to it. A pattern that works well is one folder per subject, with raw DICOM inside and converted output in a parallel tree:
- Raw data: study/raw/sub-01, study/raw/sub-02, and so on
- Converted data: study/converted/sub-01, study/converted/sub-02, and so on
That separation matters. Raw DICOM stays untouched, which is important for privacy and for re-running conversions with different settings. Converted data lives somewhere you can browse, back up, and share without touching the originals. If your incoming data already follows a different layout, spend the time to normalize it once, with a script, rather than fighting it in every batch.
Also decide your naming convention before the batch, not during it. Pick a filename pattern with -f that stays unique across series and subjects, and write it down. A batch that produces inconsistent names is barely better than no batch at all, because the cleanup afterward eats whatever time you saved.
A simple loop that does the job
On Linux and macOS, a shell loop is the workhorse. The shape is simple: for each subject folder, run dcm2niix with your chosen flags and an output folder for that subject. In outline it looks like this:
for d in study/raw/sub-*; do sub=$(basename $d); dcm2niix -z y -f "%f_%p_%s" -o study/converted/$sub $d; done
Read it slowly. For each folder matching study/raw/sub-*, it takes the subject name, runs dcm2niix with compression on, a BIDS style filename pattern, and an output folder for that subject. That is the whole engine. On Windows, the same idea works in PowerShell or a batch file with a loop over folders, and the dcm2niix flags stay exactly the same.
Keep the loop in a script file, not just in your terminal history. A saved script is rerunnable, shareable, and auditable. When a reviewer asks how your data was converted, the script is the answer.
Why the GUI is the wrong tool for big batches
The MRIcroGL converter interface is lovely for learning and for one off conversions. Drag a folder, watch it convert, done. For dozens or hundreds of subjects it becomes tedious, and tedium breeds mistakes: a folder skipped, a setting mistyped, a result saved in the wrong place. The command line removes that human variability. Every subject gets the same flags, the same naming, and the same output layout, and the script logs what happened.
That said, the GUI still has a role in batch work. Use it to convert one representative subject first, check the command it shows you, and confirm the settings produce the output you expect. Then paste those exact flags into your loop. You get the GUI’s guidance and the command line’s scale.
Checking a batch without opening every file
A batch that you do not check is a batch you do not trust. You do not need to open every image, but you do need systematic checks:
- Count outputs per subject. Every subject should produce the expected number of NIfTI files and JSON sidecars. A subject with fewer outputs than its peers deserves a look.
- Scan the logs. Save dcm2niix output to a log file per subject or one combined log. Search it for warnings and for series that converted unexpectedly.
- Spot check images. Open a random sample of converted volumes in a viewer. Check orientation, completeness, and that diffusion scans have.bval and.bvec files.
- Check sidecars in bulk. A quick script that reads every JSON sidecar and reports repetition times or phase encoding directions will surface protocol drift across subjects fast.
When a subject fails, resist the urge to patch it quietly by hand and move on. Note what was different, fix the cause if it affects others, and rerun that subject with the same script so its provenance matches the rest.
Common batch traps
Big batches have their own failure modes. Watch for these:
- Wildcards in the command. Never pass *.dcm to dcm2niix. The shell expands it into a giant argument list and the tool can crash with “Argument list too long”. Pass folders, always.
- Mixed folder depths. If some subjects have series in subfolders and others do not, a single loop may miss data. Normalize depths first, or use -n -1 to inspect odd subjects before converting them.
- Disk space. Uncompressed NIfTI output for a large study is big. Use -z y for compressed output and check free space before a long run, not during it.
- Overwriting. If you rerun a batch into the same output folders, old files can linger alongside new ones. Either clean output folders before rerunning, or use a fresh output tree for each run.
- Privacy leaks. Batch output is easy to share widely, which makes it easy to share wrongly. Confirm anonymization settings (-ba y for sidecars) and keep raw DICOM on secured storage only.
Rerunning and versioning your conversions
Conversions are rarely one and done. A scanner software update, a new dcm2niix release, or a corrected protocol can all justify a rerun. Make reruns painless: keep the conversion script under version control, record the dcm2niix version used, and keep raw data untouched so any rerun starts from the same source. If results change between runs, your script and version notes tell you why, instead of leaving you guessing.
For studies that feed BIDS datasets or fMRIPrep, the batch script is also the first half of your BIDS conversion. dcm2niix output still needs placing and renaming into BIDS folders, which our BIDS guide covers, but a clean batch makes that second half far easier.
Logging and proving a batch ran correctly
A batch without a log is a story, not evidence. Save the output of every dcm2niix run, either into one combined log file or one log per subject, and keep those logs with the converted data. A good log answers three questions later: which version of dcm2niix ran, which flags were used, and which series were found in each subject. When a collaborator asks how a dataset was produced, or when a result looks odd months later, the log is your first witness. Some labs also save a short summary per batch: subject count, total series converted, and any subjects that needed special handling. That summary takes minutes to write and saves hours of detective work when a study is audited or extended.
Conclusion
Batch conversion with dcm2niix is mostly about discipline, not cleverness: tidy folder layouts, a saved loop with consistent flags, output separated from raw data, and systematic checks after every run. Start from one GUI conversion to learn the flags, turn those flags into a script, and let the command line carry the volume. Done this way, converting a whole study is a routine step you can trust, rerun, and hand over, instead of a weekend of clicking.
Read next:
