FIND and redirect to a Variable for use at command line

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%"

LVL 39
Who is Participating?
lbertaccoConnect With a Mentor Commented:
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.
BillDLAuthor Commented:
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 :-)
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).

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

BillDLAuthor Commented:
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.
SteveGTRConnect With a Mentor Commented:
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,

BillDLAuthor Commented:
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.
All Courses

From novice to tech pro — start learning today.