1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Batch File Help

Discussion in 'DOS/Other' started by lennep, Jul 19, 2007.

Thread Status:
Not open for further replies.
Advertisement
  1. lennep

    lennep Thread Starter

    Joined:
    Jul 19, 2007
    Messages:
    8
    Can someone help with batch file? OS is XP Pro.

    We are trying to delete or keep files based on a "tag" within the target file.

    The file type is dicom (.dcm), the standard medical imaging format. One of the "tags" within the individual dicom file identifies its source, i.e xray, CT, MRI or ultrasound.

    We have a command line utility that can identify the required the tag within a .dcm file and save it to the same directory as the dicom file as a .txt file with the same name.

    For example, a new file image1.dcm is identified in the parent directory and the utilility identifies it as a CT file. It creates a new file called image1.txt containing text "CT" in the same directory.Image2.dcm may be an ultrasound, and when identified, the file image2.txt which contains text "US"is created in the same directory .

    The directory now contains 4 files: image1.dcm; image2.dcm: image1.txt: image2.txt.

    I only want to keep files with the "CT" tag and delete the others.

    The question is:

    How can we create a batch file which compares the .txt/.dcm files of the same name and deletes image2.dcm based on the "US" identifier whilst keeping image1.dcm based on its "CT" identifier.

    I presume there must be a "true" or "false" argument created by comparing the .txt and .dcm files based on the .txt file script content.

    If the script is "CT", the argument is true and the file is left intact. If the script is "US", the argument is false and then DEL file command instruction issued to remove image2.dcm.

    I know this seems messy but all of our attempts to tackle this one have failed due to our rudimentary DOS skills.

    Any assistance appreciated.

    lennep
     
  2. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    I am wondering if you could do this with the Builtin functionality of XP. Since these are digital images, they should have some type of tag that says Camera model or something. You can chose that as one of the details to show in Explorer. You can then sort by that column and select the images you want. Of course I don't know if XP will see a DCM file as an Image and show you the correct tags.
     
  3. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Basically what you need is a piece of software that can organize your Dicom images by its tag information. There seems to be alot of software out there that does this already. This is very similar to all the software out there that does this with the EXIF information tags of a normal digital camera you would buy.

    I did various Google searches with DICOM in the search parameters and I am sure you can find some software that does this for you instead of having to screw around with a Batch File.
     
  4. dez_666

    dez_666

    Joined:
    May 29, 2007
    Messages:
    842
    I dont know if this will help you, but XnView can read Dicom (*.dcm) files.
     
  5. lennep

    lennep Thread Starter

    Joined:
    Jul 19, 2007
    Messages:
    8
    I wish it were that simple.

    What we are currently doing is copying new images which are being constantly sent a network directory from various imaging modalities (CT,MRI, ultasound etc) to a local drive C:\temp. This is easily done by a nice program called WatchDirectory which monitors a drive and immediately copies newly created files to \temp. No problems there.

    WatchDirectory also monitors C:\temp for new file arrivals. When they arrive, it launches the .bat below which I created after much research on various forums. It selects and deletes files samller than 450kb and larger than 910kb and then imports the remaining images into the program EFilm, a medical viewer. The -d then deletes the imported images once the run is completed. This size range selects the modalites I want to keep reasonably well and deletes the rest before Efilm Import starts.

    Unfortunately, some of the images I want to keep from MRI are in the 150kb range and are therefore deleted before import. Whilst I could drop my delete size, this would select a large number of unwanted files.

    Using the utility that finds an image tag and creates an associated txt file identifes the source of the image as being CT, MRI etc., but it does not have the ability to do anything other than write a text file with the content 'CT', 'MRI' etc with the same file name as the original image.

    Hence my question - as my current batch file only selects on the basis of size, can I write one that compares txt and dcm files and deletes or keeps dcm on the basis of the txt script? I only want to keep CT and MRI.

    cd\temp
    FOR %%F IN (*.*) DO (
    IF %%~zF LEQ 450000 DEL %%F
    IF %%~zF GEQ 910000 DEL %%F
    )
    "C:\Importer\wscript.exe "C:\Importer\invisible.vbs""
    "C:\Program Files\Merge eFilm\eFilm\efDcmIm.exe" C:\temp -d
    exit


    lennep
     
  6. dez_666

    dez_666

    Joined:
    May 29, 2007
    Messages:
    842
    Why not just make different directories and import a directory?

    Like have one kind of image be sent to one folder, another kind to another folder, and then when they are transferred they would appear as

    C:\temp\MRI\anmrifile.dcm
    C:\temp\CT\aCTfile.dcm

    like that..?
     
  7. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    If this utility it a command line utility, you should be able to redirect stdout to a utility like grep. Tell grep to look for CT and if true then move the file it is working on to another directory.
     
  8. ghostdog74

    ghostdog74

    Joined:
    Dec 7, 2005
    Messages:
    146
    no batch..but vbscript.
    Code:
    Option Explicit
    Dim myDir,objFSO,objFolder,Files,FileExt,FileName,objFile
    Const ForReading=1
    myDir="c:\temp"
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    Set objFolder = objFSO.GetFolder(myDir)
    For Each Files In objFolder.Files
    	FileExt = objFSO.GetExtensionName(Files)
    	If  FileExt = "dcm" Then
    		FileName=objFSO.GetBaseName(Files)
    		If objFSO.FileExists(myDir&"\"&FileName & ".txt") then
    			Set objFile = objFSO.OpenTextFile(myDir&"\"&FileName & ".txt", 1)
    			Do Until objFile.AtEndOfLine
    			  If InStr(1,objFile.ReadLine,"US")  Then
    			  	objFSO.DeleteFile(myDir&"\"&FileName & "."&FileExt)
    			  End If 
    			Loop
    			Set objFile = Nothing
    		End If 
    	End If
    Next
    
     
  9. Squashman

    Squashman Trusted Advisor

    Joined:
    Apr 4, 2003
    Messages:
    19,786
    Where is it checking to see if image.txt contains CT?
     
  10. Sponsor

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 733,556 other people just like you!

Loading...
Similar Threads - Batch File Help
  1. niedernsill
    Replies:
    3
    Views:
    368
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/597725

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice