We help IT Professionals succeed at work.

Instal.bat question

RICHARDH
RICHARDH asked
on
I am writing an install file which will copy some files from a CD-ROM to a hard drive.

I can use a line such as...

copy d:\users.txt c:\champs\users.txt

But this only works if the user's CD is the 'D' drive. As the install program is being run from the CD is there a way of copying from the current drive to the C drive or a way of finding which drive the CD-ROM is in.

Thanks for the help
Comment
Watch Question

Commented:
If the batch file is run from the CD by clicking on it in explorer then the current directory for the batch file will be the CD drive letter and so you could get away with a relative path like...
    copy users.txt c:\champs\users.txt


However a safer way would be to detect the presence of a known file e.g.

  rem -- First check current directory
  if exist somefile.txt goto doinstall
  rem -- now check drive letters and if found change drive
  if exist D:\somefile.txt cd D:
  if exist E:\somefile.txt cd E:
  rem -- Repeat the above for F: G: H: etc....

  cd \

  :doinstall
  copy users.txt c:\champs\users.txt


Author

Commented:
A problem I am afraid.

If I have a line such as

if exist D:\somefile.txt cd G:

If the drive with letter 'G' does not exist on the system then the Install.bat file stops with an error message.

Any suggestions.

Thanks for the help..
Richard.

Author

Commented:
A problem I am afraid.

If I have a line such as

if exist D:\somefile.txt cd G:

If the drive with letter 'G' does not exist on the system then the Install.bat file stops with an error message.

Any suggestions.

Thanks for the help..
Richard.

Commented:
Actually I did make a minor mistake - to reiterate the "if" statements should be of the form :

  if exist X:\somefile.txt X:


That is ....


 rem -- First check current directory
 if exist somefile.txt goto doinstall

 rem -- now check drive letters DEFGHI and if found change drive
 if exist D:\somefile.txt D:
 if exist E:\somefile.txt E:
 if exist F:\somefile.txt F:
 if exist G:\somefile.txt G:
 if exist H:\somefile.txt H:
 if exist I:\somefile.txt I:
 cd \

 :doinstall
 copy users.txt c:\champs\users.txt


Commented:
Which OS family?  NT/2K/XP, 9x/Me or DOS?

Commented:

It's an OLD DOS trick

@echo off
copy %0\..\users.txt c:\champs\users.txt

try it and let me know :-)

regards

Commented:
>> copy %0\..\users.txt c:\champs\users.txt

What happens if run from a nested subdirectory?

Commented:

No problem; the shell uses it as follows:

Let's say %0 contains something like:

D:\SETUP\DISK1\INSTALL.BAT

when You use that syntax the "source dir" will be

D:\SETUP\DISK1\INSTALL.BAT\..\USERS.TXT

now the shell will follow the path and treat INSTALL.BAT ... as a SUBDIR so that

\setup\disk1\install.bat\..

will become

\setup\disk1

so ... You see it by Yourself

Give it a try and You'll see !

This trick comes straight from DOS 3.30 and MS mantained it for compatibility through each and every new O/S

Regards






Commented:
Hey now that's a smart trick!
RICHARDH:

You have many open questions:

http://www.experts-exchange.com/jsp/qShow.jsp?qid=11342298
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11355858
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11382838
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11415199
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11670638
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20001107
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20004454
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20065368
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20073152
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20084825
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20084821
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20086663
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20086784
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20107892
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20109405
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20109357
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20109887
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20110886
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20117400
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20118020
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20118934
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20118648
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11342618
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20130049
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20132692
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20142937
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20146293
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20147289
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20148615
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20149087
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20148609
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20150501
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20150630
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20154720
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20154865
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20154980
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20155947
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20180018
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20189434
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20193459
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20222409
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20235436
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20244279
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20244276
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20193051
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20256056
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20257136
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20257135
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20127746
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20259971
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20259964

To assist you in your cleanup, I'm providing the following guidelines:

1.  Stay active in your questions and provide feedback whenever possible. Likewise, when feedback has not been provided by the experts, commenting again makes them receive an email notification, and they may provide you with further information. Experts have no other method of searching for questions in which they have commented, except manually.

2.  Award points by hitting the Accept Comment As Answer button located above and to the left of that expert's comment.

3.  When grading, be sure to read:
http://www.experts-exchange.com/jsp/cmtyQuestAnswer.jsp#3
to ensure that you understand the grading system here at EE. If you grade less than an A, you must explain why.

4.  Questions that were not helpful to you should be PAQ'd (stored in the database for their valuable content?even if not valuable to you) or deleted. To PAQ or delete a question, you must first post your intent in that question to make the experts aware. Then, if no experts object after three full days, you can post a zero-point question at community support to request deletion or PAQ. Please include the link(s) to the question(s).
CS:  http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
At that point, a moderator can refund your points and PAQ or delete the question for you. The delete button does not work.

5.  If you fail to respond to this cleanup request, I must report you to the Community Support Administrator for further action.

Our intent is to get the questions cleaned up, and not to embarrass or shame anyone. If you have any questions or need further assistance at all, feel free to ask me in this question or post a zero-point question at CS. We are very happy to help you in this task!


thanks!
amp
community support moderator

1/27

Author

Commented:
Sorry about the delay.
Am clearing up my account and discovered that I had now awarrded you the points for this anser.

Thanks fior the assistance with this problem.

Regards

Richard.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.