FIND and redirect to a Variable for use at command line

Posted on 2004-04-25
Last Modified: 2012-06-21
Hello all.

I really should know this but I've got a mental block.  Can somebody please suggest a simple correction to the problem area.  I've simplified the real paths in this example.  It's really just a quick and dirty way I thought of for my father to copy images from the compact flash card of a digital camera into a holding folder, and then immediately open them in thumbnail view in an image browser (IrfanView) with the first image already open in the viewer window.

In case you are wondering, I installed NikonView, which came on CD with the camera, and this launches the "transfer" dialogue when the camera is connected.  It then opens the thumbnail browser once transfer is complete.  My father already uses IrfanView for viewing, batch resizing, batch conversion and renaming, colour corrections, slideshows, etc.  I have a feeling that opening the images in IrfanView would make things easier than finding his way around a clunky and limited program which really is just an intermediate step.  It certainly isn't a useful "editor", and keeps forgetting the user preferences I set.  It also crippled Norton AntiVirus during an uninstall after it froze up and greyed out a dialogue and menu option, so I don't feel like using  it again.  Apart from that, it is incredibly easy to "Move to..." or "Copy To..." with right-clicks.

Call it an experiment, if you will, but I wouldn't mind getting this idea to work, unlike my memory of DOS at the moment :-)

DOS 7.10 in the Windows Environment of Win98SE and launched from a desktop shortcut.

@echo off
SET DEST=c:\images\holding
SET ROOT=c:\images
SET PROGDIR=c:\progra~1\irfanv~1\
COPY %SOURCE%\*.jpg  %DEST%\*.jpg
DIR /b /on %DEST%\*.jpg > %ROOT%\list.txt
:: This results in a list of filenames only.
:: need something to strip the top line of
:: list.txt and save it to a variable that
:: can be added to a command line to run
:: the image browser and open that image.
:: *** This is where I stumble.  I'm not sure of
:: *** how to direct the "find" results to associate
:: *** the string with the variable "FIRST".
:: *** Here's the obviously wrong syntax, but
:: *** gives the general idea of what I want :-)
SET FIRST= < type %ROOT%\list.txt | find /i "01.jpg"
:: Using the "01.jpg" eliminates the chance that
:: files "image_0011.jpg", etc, are found also.
:: This isn't the real naming convention, just an example.
:: Assuming the first line of list.txt to be
:: image_0001.jpg (as created by a naming convention
:: of the camera that created the images in "SOURCE"),
:: I had thought that I could use the variable
:: "FIRST" something like this
START %PROGDIR%\i_view32.exe  %DEST%\%FIRST%
ECHO       The camera's flash card is empty
ECHO       Press any key to end...

I know the useful Irfanview command line switches, and I would use something like the following, but have left them out for now:

START %PROGDIR%\i_view32.exe %DEST%\%FIRST% /thumbs /ini="%PROGDIR%"

Question by:BillDL
  • 3
  • 2
LVL 38

Author Comment

ID: 10915700
OK, I noticed an error straight off in my example, but it's just a typo that I wouldn't have overlooked.  The path to the Program File is "SET" to ":\progra~1\irfanv~1\" ie. inclusive of the last \ which shouldn't be there.  The .exe is later called with the %Variable%\Program.exe and this would have failed.

Just before you comment on this :-)
LVL 11

Expert Comment

ID: 10916757
Well, this is quite hard with win98 msdos. THe only idea that comes to mind is:

copy setcmd.bat tmp.bat
type %ROOT%\list.txt | find /i "01.jpg >>tmp.bat
call tmp.bat

where setcmd.bat is just the line
set first=

but without a crlf at the end (that's why you can't use ECHO to create this file).

LVL 38

Author Comment

ID: 10918484
Thanks, lbertacco.

So you're concatenating the line with an existing one.  I had wondered about doing something like this, but assumed that this would append the new line as a fresh line below the existing SET command.  In fact, I remember trying to create a command line in this way when using 16-bit C programming where I used the "SYSTEM" command and tacked my variables onto the line before executing it.

I've always had that happen when I have used the >> redirector, but this has probably been because I didn't backspace up to the last character of the file containing the partial command before saving it, which would in this case be the = sign.

I will try and apply this to my situation and see how this works.  Maybe I will dredge out my old Borland Turbo C again and have a go if I can't get this to work.  I don't know enough about Visual Basic or C++ and it kind of defeats the purpose of keeping it simple anyway.
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

LVL 30

Assisted Solution

SteveGTR earned 100 total points
ID: 10918808
You could make a file named setcmd.txt:

set start=

Run debug and enter the following:

debug setcmd.txt
r cx

This will trim the CR+LF.

Then you could say:

copy /b setcmd.txt+list.txt temp.bat
call temp.bat

The only problem is that the temp.bat file will have all the other potential jpg files in it and try to execute them using the default program.

Good Luck,

LVL 11

Accepted Solution

lbertacco earned 100 total points
ID: 10921958
the newline is not added by the >> redirection. Usually it's added by the command that creates the first line.
If you do "echo set  first=>>setcmd.bat", then echo appends the crlf and this is not going to work.
To create a file with "set first=" (without any newline at the end), you can use a good editor that let you specify that you don't want the end-of-line crlf (e.g. ultraedit), a debugger (as SteveGTR suggests), standard unix tools (e.g. unix echo -n or dd), enhanced dos tools (e.g. 4nt) or create it programmatically.
Let me know if you need further help on this.
LVL 38

Author Comment

ID: 10924425
Thank you guys.

Steve, I immediately recognise the "copy   file1+file2   file3"  syntax as being something I used before a while ago.  I had forgotten this, and I'm glad you brought it up, because I believe I can see how to do this.  I hadn't thought of using debug and then using the /b switch on the copy command.  That's interesting, and I'll look into this.

lbertacco, tahnks for the explanation about the crlf.  I hadn't considered that too carefully.  Yes, I think Metapad has the option to create text files with the crlf stripped off, or at least convert it to a unix format.

I'm splitting the points between both of you even though I don't have a functional result to paste here.  It will take me a few days to look at, and it's not too high on my priority list, but will paste the results once done so that it is resolved for PAQ purposes.

Thank you.

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Using dates in 'DOS' batch files has always been tricky as it has no built in ways of extracting date information.  There are many tricks using string manipulation to pull out parts of the %date% variable or output of the date /t command but these r…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question