 | Junior Member with 8 posts. | | Join Date: Jul 2007 Experience: Intermediate | | Solved: batch file help Hi,
We require some help refining a batch file to compress large numbers of medical image files using a utility called "dcmcjpeg.exe".
We have created a batch file into which we drag and drop the images files which are then compressed and overwrite the originals.At present, the images are stored in multiple sudirectories and must be located with a manual search. The "+ee" parameter shown below is the type of compression used.
To overcome the batch file's limitation to only handle parameters up to %9, we use the SHIFT command and repeat the original command many times over, making for a long and cumbersome batch file with limitations on the number of images than can be processed due to command line length limitations.
The batch file and dcmcjpeg.exe reside in a C: drive folder called "compress":
[i][cd\compress
dcmcjpeg +ee %1 %1
SHIFT
dcmcjpeg +ee %1 %1
SHIFT
dcmcjpeg +ee %1 %1
SHIFT
dcmcjpeg +ee %1 %1
SHIFT/I] etc.etc.
Is there a more elegant way of looping the original command and allowing drag and drop of the parent folder with processing of images in all subdirectories?
Thanks in advance. | | Distinguished Member with 14,988 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | You would be better of using a For Loop to parse the directory and sub directories instead of dragging and dropping the files on there. I am kind of surprised that it will let you overwrite a file in use. That doesn't make a whole lot of sense.
I will whip up a batch file tonight when I get some free time. I will direct a few other guys over here as well. TheOutCaste is pretty darn good at this stuff. | | Junior Member with 8 posts. | | Join Date: Jul 2007 Experience: Intermediate | | Thanks for the prompt response Squashman.
We are medicos, not programmers and hence the crude nature of this effort. We initially renamed all compressed files but when I tried "%1 %1" in the command line, yes, it does overwrite the file. This is handy because we then do have to delete the original image files.
We would appreciate any rewrite of this batch file that allows for more automated importing and processing, but drag and drop of the parent folder rather than the contained subdirectory files into the batch file would still work OK for us. We are aware of For Loop but are not clear on its correct implementation. | | Distinguished Member with 5,486 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | This is a better way of writing your original as you don't have to guess at how many files are dropped. You are still limited to the 8191 character limit, which includes the batch file name. Code: @Echo Off
:_Process
If [%1]==[] Goto :_Done
dcmcjpeg +ee %1 %1
SHIFT
Goto _Process
:_Done
PopD
Pause You can remove the Pause statement to have it automatically close when finished
This file will let you drop a folder onto the batch file icon (or a shortcut to the icon you can place on the desktop) and will process all files in that folder and it's subfolders:
You can adjust the width and height of the Command Prompt window by adjusting the numbers in the 6th line, or remove it to use the defaults. I set it to widen the window a bit so longer paths will be visible in the title bar.
You can remove the Pause statement in line 11 to have it automatically close when finished, but leave the last Pause statement in. Code: @Echo Off
If [%1]==[] Goto _Usage
If Not Exist "%~1" Goto _Usage2
If Not Exist %~s1\nul Goto _Usage1
Set _Source=%1
Mode CON: Cols=100 Lines=30
Title Processing %_Source% and it's subfolders
PushD "%~dp0"
For /F "Tokens=1 Delims=" %%I In ('Dir /A-D /B /S %_Source%') Do dcmcjpeg +ee "%%I" "%%I"
PopD
Pause
Goto :EOF
:_Usage2
Echo Error: %1 does not exist.
Goto _Usage
:_Usage1
Echo Parameter Error: %1 is a file name.
Echo : Please specify a folder name
:_Usage
Echo.
Echo %~n0 [drive:][path]foldername
Echo.
Echo. foldername : Name of the folder to process.
Echo. : It must be quoted if it contains spaces and is entered
Echo. : on the Command Line. If dropped on the batch file or it's
Echo. : shortcut, it will be quoted automatically
Echo.
Pause
HTH
Jerry
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations?
Last edited by TheOutcaste : 14-Oct-2009 01:45 PM.
Reason: Removed Echo used for testing
| | Distinguished Member with 14,988 posts. | | Join Date: Apr 2003 Location: 1265 Lombardi Ave Experience: IIAHYAYCESA,YAADA! | | Keeping it simple. That is awesome Jerry. | | Junior Member with 8 posts. | | Join Date: Jul 2007 Experience: Intermediate | | Hi TheOutcaste,
Thanks for tthis. Clearly your solution is way beyond anything we could have conceived. I am away for a couple of days but will test the new files as soon a possible upon my return.
Once again, thanks for the incredibly fast responses from yourself and Squashman.. | | Distinguished Member with 5,486 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate | | You're welcome, let us know how it goes. | | Junior Member with 8 posts. | | Join Date: Jul 2007 Experience: Intermediate | | Thanks guys, the file posted by Outcaste works at treat for both folders and subfolders.
lennep | | Junior Member with 8 posts. | | Join Date: Jul 2007 Experience: Intermediate | | Hi Outcaste,
Wondering if I could get a little more help? We now have a very functional system in operation based on your batch file, and again, thanks for your help.
We do, however, now have a problem with some vendor images rendered unreadable with compression type "+ee". These are readable with a less efficicient compression type "+e1".
As the files affected are less than 1.5mb, can we do a modification that requests that files less than 1.5mb are compressed by "dcmcjpeg +e1" and those larger than 1.5mb are compressed by "dcmcjpeg +e1" ?
Regards,
lennep | | Distinguished Member with 5,486 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate |
28-Oct-2009, 04:11 AM
#10 | Quote:
Originally Posted by lennep files less than 1.5mb are compressed by "dcmcjpeg +e1" and those larger than 1.5mb are compressed by "dcmcjpeg +e1" | I'm assuming the +e1 should be +ee
So files 1.5 MiB (1,572,864 bytes) or larger will use +ee and files less than 1.5 MiB will use +e1.
Just need to add a check for file size in the For loop in line 9.
It will now cover lines 9 through 14, pushing the PopD statement that was on line 10 to line 15: Code: For /F "Tokens=1 Delims=" %%I In ('Dir /A-D /B /S %_Source%') Do (
If %%~zI GEQ 1572864 (
dcmcjpeg +ee "%%I" "%%I"
) Else (
dcmcjpeg +e1 "%%I" "%%I"
))
Give that a try.
Jerry
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? | | Junior Member with 8 posts. | | Join Date: Jul 2007 Experience: Intermediate |
28-Oct-2009, 06:22 AM
#11 | Hi Jerry,
Worked perfectly!!
Just to fill you in on what we have achieved in improving xray image transfer from remote rural locations in the Australian outback for reporting.
1.We start with approx. 500 MB of dicom images files and a bunch of request forms in .pdf format
2.With a single click, a series of commands in batch files compress the dicom images, deletes junk files, compresses the lot to .rar file (final size 80MB with +ee, +e1) and deletes the original folder of images
3..rar file transfered by YouSendIt in about 40 minutes
4.Downloaded from our homes for reporting in 15 minutes.
5.A single click on a batch file then decompresses the .rar file, copies .pdf's to a defined folder, imports the dicom and opens an image viewing program and deletes the.rar and all decompressed files, leaving an empty directory for the next run.
We couldn't be more pleased with the results and thank you for your assitance in this project.
Cheers,
Ruben | | Distinguished Member with 5,486 posts. | | Join Date: Aug 2007 Location: Oregon, USA Experience: Intermediate |
30-Oct-2009, 06:46 PM
#12 | You're welcome Ruben.
Glad to hear it's working so well. If your issue has been resolved you (and ONLY you) can mark this thread Solved by using the Mark Solved button at the Top Left of this thread (above the first post)
Jerry
__________________ Microsoft MVP - Windows Desktop Experience
Of course I know all the answers  ; I just don't always match the answers to the right questions Are you aware of the New Signature Limitations? | |
Smart Search
| Find your solution! | |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | | |  WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
| You Are Using: |
Advertisements do not imply our endorsement of that product or service.
All times are GMT -5. The time now is 01:14 AM.
Copyright © 1996 - 2009 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd. | |
|