@@ -244,7 +244,10 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
244
244
lgr .info ('Converting %s (%d DICOMs) -> %s . '
245
245
'Converter: %s . Output types: %s' ,
246
246
prefix , len (item_dicoms ), prefix_dirname , converter , outtypes )
247
- if not op .exists (prefix_dirname ):
247
+ # We want to create this dir only if we are converting it to nifti,
248
+ # or if we're using BIDS
249
+ dicom_only = len (outtypes ) == 1 and outtypes [0 ] == 'dicom'
250
+ if not (dicom_only and bids ) and not op .exists (prefix_dirname ):
248
251
os .makedirs (prefix_dirname )
249
252
250
253
for outtype in outtypes :
@@ -254,6 +257,9 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
254
257
255
258
seqtype = op .basename (op .dirname (prefix )) if bids else None
256
259
260
+ # set empty outname and scaninfo in case we only want dicoms
261
+ outname = ''
262
+ scaninfo = ''
257
263
if outtype == 'dicom' :
258
264
convert_dicom (item_dicoms , bids , prefix ,
259
265
outdir , tempdirs , symlink , overwrite )
@@ -299,17 +305,17 @@ def convert(items, converter, scaninfo_suffix, custom_callable, with_prov,
299
305
"multiple files" )
300
306
elif not bids_outfiles :
301
307
lgr .debug ("No BIDS files were produced, nothing to embed to then" )
302
- else :
308
+ elif outname :
303
309
embed_metadata_from_dicoms (bids , item_dicoms , outname , outname_bids ,
304
310
prov_file , scaninfo , tempdirs , with_prov ,
305
311
min_meta )
306
- if op .exists (scaninfo ):
312
+ if scaninfo and op .exists (scaninfo ):
307
313
lgr .info ("Post-treating %s file" , scaninfo )
308
314
treat_infofile (scaninfo )
309
315
310
316
# this may not always be the case: ex. fieldmap1, fieldmap2
311
317
# will address after refactor
312
- if op .exists (outname ):
318
+ if outname and op .exists (outname ):
313
319
set_readonly (outname )
314
320
315
321
if custom_callable is not None :
0 commit comments