Solved

Batch file

Posted on 2001-09-14
12
381 Views
Last Modified: 2012-08-14
How do you reference the current path?

Reason being, I'm trying to write an autostart CD to launch a browser window. Say, IEXPLORE -k d:\filename.html

However, the letter of the drive is going to vary from PC to PC, so how do I reference the drive letter?

Cheers,
David
0
Comment
Question by:dht1
  • 5
  • 2
  • 2
  • +3
12 Comments
 
LVL 10

Expert Comment

by:Longbow
ID: 6482796
If you don't give a drive letter current disk and path will be used.
Sinds autorun will be launched from the CD i think it will be ok.
1st make a test on a partition and create an autorun.inf there. So you may test your application before burning the CD
0
 
LVL 3

Expert Comment

by:czpczp
ID: 6482913
David, w/o knowing how you're writing your script and not knowing what OS you're working on, it's a little hard to provide many suggestions.

But, based on what you're asking so far, the "Change Directory" (CD) command will give you the exact drive and path that you're working off of.

<e.g.>

typing "CD" on the following drives/paths produces the following:


D:\> CD
produces --  D:\

E:\MyDir> CD
produces --  E:\MyDir

F:\MyDir\Files> CD
produces --  F:\MyDir\Files


If this is not helpful, please provide more info (like an example of your script and your OS).
0
 
LVL 7

Expert Comment

by:rin1010
ID: 6482971

David,

When you say "reference the current path" do you mean the drive letter
of the users cdrom drive? (And not the path to iexplore.exe?)
As Lonbow notes, you won't need to supply a path if the file being sought
is in the current directory. Using the example you posted would be like:

iexplore -k filename.htm

A backslash preceding a path indicates the root directory,
so if 'filename.htm' is in a directory named Docs on the CD
you could reference it like:

iexplore -k \docs\filename.htm

Note that the working directory is from where the .inf file is run,
so if filename.htm is in the root directory of your CD
then you could also reference it like:

iexplore -k \filename.htm

Hope this makes it work for you... Please post back
if it's not what you meant or if you want more about it...
 
0
 

Author Comment

by:dht1
ID: 6482985
The script is simply attempting to open an HTML document with internet explorer.

The problem is that my CD drive may be d:\ but yours might be e:\

The operating system is Windows.

There is a copy of Internet Explorer on the CD.

If I say IEXPLORE -k d:\filename.html it works fine however, may not work on someone else's machine so all I need is some method of replacing the "d:\" part of the command.

For instance $n works fine in a command such as:
prompt $n

However, I can't simply transfer $n to the command I'm trying to use since this literally outputs $n.

Hopefully this makes more sense...????

Cheers,
David
0
 
LVL 47

Expert Comment

by:dbrunton
ID: 6483124
You may need a util to get the CDROM drive letter (D: or E:) and then place that in the enviroment.  Say that it stores it in

CDROMENV=D:

for example

Then you could then reference it as

iexplore    -k     %CDROMENV%\filename.html

In your script run the util first and then call the iexplore line.
0
 

Author Comment

by:dht1
ID: 6483212
Any idea how I get the CDROM letter?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:dht1
ID: 6483215
Any idea how I get the CDROM letter?
0
 
LVL 3

Expert Comment

by:czpczp
ID: 6483220
The following will work on Windows NT but not with 9x.  It creates a environment variable of the current drive (cdrom) and stores it to a var called "CDR".  Then you can simply reference it using %CDR% in the command line.  This won't work under 9x 'cause of the differences in the FOR statement.


for /f %%a in ('CD') do set CDR=%%a

iexplore  -k  %CDR%filename.html



In the above example, if your CD drive was D:\ then CDR will equal D:\
0
 
LVL 5

Expert Comment

by:PatOBrien
ID: 6483222
why not test for the existance of the file....

if exist d:\filename.html IEXPLORE -k d:\filename.html
if exist e:\filename.html IEXPLORE -k e:\filename.html

Pat
0
 

Author Comment

by:dht1
ID: 6483266
That works great!

However, while testing it, if someone's CD drive is e:\ and d:\ happens to be a floppy or zip drive with no disk in it, it chucks up an error. How can I prevent errors being thrown, or forcing it to fail?
0
 
LVL 7

Accepted Solution

by:
rin1010 earned 50 total points
ID: 6483423

David,

You said you need "some method of replacing the "d:\" part of the command."
If iexplore.exe and the html file reside on the cd then is my suggestion of the backslash
not working to point to the root of the cd drive or a specific path on the cd?
You mentioned, "If I say IEXPLORE -k d:\filename.html it works fine..."
Where are you "saying" this? Is this the open= line of an autorun.inf file?

There are methods (using commands you have) to get the cdrom drive's current drive letter,
including the use of its volume label (if you're creating one on the cd.)
But if everything is running from the cd, then preceding the path to your files with a backslash
should always indicate the drive's current root regardless of its drive letter.

If you're referring to the "if exist" command causing the error and you're getting the
"Not ready reading drive x ... Abort, Retry, Fail?" message,
try it with the command.com /f switch to bypass the arf error, like

%comspec%/f/c if exist [filename] [command]

Post back if you want other methods and whether you need
just a one line command or if you're doing this from a batch script.
 
0
 

Author Comment

by:dht1
ID: 6487031
Thanks also to PatOBrien
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Full screen legacy Dos app in VirtualBox 14 367
Script to copy every 7th file 10 54
MailSend Attachments 41 116
robocopy vs xcopy vs copy 8 55
VALIDATING DATES One method of validating dates is to jam the date into the DATE command and see if it accepts it by examining the system's errorlevel value. A non-zero result indicates failure. A typical example might look something like the fol…
YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

707 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

17 Experts available now in Live!

Get 1:1 Help Now