Solved

FIND and redirect to a Variable for use at command line

Posted on 2004-04-25
6
1,205 Views
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 SOURCE=H:\DCIM\100NIKON
SET DEST=c:\images\holding
SET ROOT=c:\images
SET PROGDIR=c:\progra~1\irfanv~1\
::
IF NOT EXIST %SOURCE%\*.jpg  GOTO :EMPTY
::
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%
GOTO :END
:EMPTY
CLS
ECHO.
ECHO       The camera's flash card is empty
ECHO.
ECHO       Press any key to end...
PAUSE>NUL
:END
SET FIRST=
SET SOURCE=
SET DEST=
SET ROOT=
EXIT

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

Thanks
Bill
0
Comment
Question by:BillDL
  • 3
  • 2
6 Comments
 
LVL 38

Author Comment

by:BillDL
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 :-)
0
 
LVL 11

Expert Comment

by:lbertacco
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).



0
 
LVL 38

Author Comment

by:BillDL
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.
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 30

Assisted Solution

by:SteveGTR
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
a
w
q

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,
Steve

0
 
LVL 11

Accepted Solution

by:
lbertacco earned 100 total points
ID: 10921958
BillDL,
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.
0
 
LVL 38

Author Comment

by:BillDL
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.
   
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

The following is a collection of cases for strange behaviour when using advanced techniques in DOS batch files. You should have some basic experience in batch "programming", as I'm assuming some knowledge and not further explain the basics. For some…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

708 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now