There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
DOS/Other
Tag Cloud
access acer asus bios bsod computer crash drive driver drivers error ethernet excel freeze games gaming hard drive hardware hdmi internet java laptop malware memory monitor motherboard music network obp printer problem ram random registry router slow software sound trojan usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > DOS/Other >
Solved: batch file help

Reply  
Thread Tools
lennep's Avatar
Junior Member with 8 posts.
 
Join Date: Jul 2007
Experience: Intermediate
13-Oct-2009, 08:27 PM #1
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.
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
13-Oct-2009, 09:04 PM #2
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.
lennep's Avatar
Junior Member with 8 posts.
 
Join Date: Jul 2007
Experience: Intermediate
13-Oct-2009, 11:56 PM #3
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.
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
14-Oct-2009, 02:09 PM #4
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 Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions


Last edited by TheOutcaste; 14-Oct-2009 at 02:45 PM.. Reason: Removed Echo used for testing
Squashman's Avatar
Trusted Advisor with 18,705 posts.
 
Join Date: Apr 2003
Location: 1265 Lombardi Ave
Experience: Bocks of Rox
14-Oct-2009, 02:28 PM #5
Keeping it simple. That is awesome Jerry.
lennep's Avatar
Junior Member with 8 posts.
 
Join Date: Jul 2007
Experience: Intermediate
14-Oct-2009, 04:23 PM #6
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..
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
14-Oct-2009, 04:50 PM #7
You're welcome, let us know how it goes.
lennep's Avatar
Junior Member with 8 posts.
 
Join Date: Jul 2007
Experience: Intermediate
23-Oct-2009, 01:44 AM #8
Thanks guys, the file posted by Outcaste works at treat for both folders and subfolders.

lennep
lennep's Avatar
Junior Member with 8 posts.
 
Join Date: Jul 2007
Experience: Intermediate
28-Oct-2009, 01:26 AM #9
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
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
28-Oct-2009, 05:11 AM #10
Quote:
Originally Posted by lennep View Post
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 Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

lennep's Avatar
Junior Member with 8 posts.
 
Join Date: Jul 2007
Experience: Intermediate
28-Oct-2009, 07: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
TheOutcaste's Avatar
Computer Specs
Distinguished Member with 9,048 posts.
 
Join Date: Aug 2007
Location: Oregon, USA
Experience: Intermediate
30-Oct-2009, 07: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 Expert - Consumer
Of course I know all the answers ; I just don't always match the answers to the right questions

Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




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.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 07:29 AM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.