Recursive conversion of jpg files

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
lennep
Posts: 3
Joined: 25 Jul 2013 06:43

Recursive conversion of jpg files

#1 Post by lennep » 26 Jul 2013 23:45

I am trying to convert a large number of .jpg files to the medical image format .dcm. There are many folders (with no subfolders) within a directory called C:\dicom. Each of these contains a patient specific .jpg called "REF.jpg" that needs to be converted to a file called "request.dcm" by using a small utility called img2dcm located in C:.

Each folder also contains a patient specific file called "IMG.dcm" used as a template for the conversion. Patient specific metadata is inserted from the template into the newly created request.dcm file.

For an individual folder called "foldername" containing the "REF.jpg" file, and the template file "IMG.dcm", the following command line (including the spaces) will create a usable "request.dcm" file in the same folder:

Code: Select all

[i]img2dcm foldername\REF.jpg foldername\request.dcm -stf foldername\IMG.dcm -k "Ser iesDescription"=REQUEST -k "Modality"=OT -k "SeriesNumber"=200 -k "ImageNumber"= 1"[/i]


What I need to do is create a batch file to loop this command through every folder in the directory, all differently named but all containing the required files. It is crucial the newly created file be placed within its parent folder.

Any help would be greatly appreciated for what is a fairly daunting project for a someone without an IT or computing background.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Recursive conversion of jpg files

#2 Post by foxidrive » 27 Jul 2013 00:08

Copy a few directories over to c:\dicom-test folder and try this. I think it should work as you described, and create the file in the same folder as the two other files.

Add the path to the img2dcm file if that is not on the system path.

Code: Select all

@echo off
pushd "c:\dicom-test"
for /d /r %%a in (*) do (
pushd "%%a"
img2dcm REF.jpg request.dcm -stf IMG.dcm -k "SeriesDescription"=REQUEST -k "Modality"=OT -k "SeriesNumber"=200 -k "ImageNumber"=1
popd
)
popd

lennep
Posts: 3
Joined: 25 Jul 2013 06:43

Re: Recursive conversion of jpg files

#3 Post by lennep » 27 Jul 2013 19:59

Thanks so much. A couple of hours of frustration before re-reading the solution, putting the path to the img2dcm file into the .bat, then all was well. :D :D

Post Reply