Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win


FIND and redirect to a Variable for use at command line

Posted on 2004-04-25
Medium Priority
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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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.
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

LVL 30

Assisted Solution

SteveGTR earned 400 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 400 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…

636 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