?
Solved

Browse CD using Batch File

Posted on 2009-02-10
10
Medium Priority
?
511 Views
Last Modified: 2012-05-06
I have a CD created which autoruns and shows a menu of options. What I would like to do is have one of the options run a batch file which will display the CD contents. The problem is that the CD drive letter could be different on users PC's. I'm not an accomplished batch file writer so full code examples would be a great help.

Many thanks.
0
Comment
Question by:jonlake
  • 4
  • 3
  • 3
10 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23606144
Well... you can get the filename of the batch file that is running using %0 and then take just the drive letter part of that like this:

@echo off
set drive=%~d0
echo The drive this runs from is %drive%
dir %drive%\*.* /s/b
pause
tree %drive%\
pause

Obviously you can do what you want with the commands, e.g. a dir listing or whatever.

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23606168
Also... if the batch file is on the cd then running it the current directory is the directory where the batch file is anyway (add echo %cd% to see the current directory in your batch file).  So you can do, for instance, dir \*.* /s to show a dir listing from the root.

@echo off
echo The current directory is %cd%
dir \*.* /s
pause
tree %drive%
pause
dir \*.* /w/s/p
pause
0
 

Author Comment

by:jonlake
ID: 23606324
Hmmm, I was hoping to open the cd in explorer using the batch file.
0
Free recovery tool for Microsoft Active Directory

Veeam Explorer for Microsoft Active Directory provides fast and reliable object-level recovery for Active Directory from a single-pass, agentless backup or storage snapshot — without the need to restore an entire virtual machine or use third-party tools.

 
LVL 21

Expert Comment

by:AmazingTech
ID: 23606334
Try it like this
%systemroot%\explorer /e,/root,%~d0

Open in new window

0
 

Author Comment

by:jonlake
ID: 23606416
AmazingTech, that works very well. Could I trouble you for just one slight modification? Is it possible to use this code to open a particular folder on the cd? For example, if the CD contained a folder called 'Audit File'.

Many thanks
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23606432
I did wonder why you wanted to show it in batch file format.... but that did seem what you wanted.  doing as amazingtech suggests should work, or just use START to launch it:

start "Your cd description" .
or
start "Your CD description" %~d0

Steve
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 23606442
Try
start "Your CD description" "%~d0\Audit File"

Steve
0
 
LVL 21

Expert Comment

by:AmazingTech
ID: 23606454
Try it this way.

You might need quotes if it doesn't work like this:
%systemroot%\explorer /e,/root,"%~d0\Audit File"
%systemroot%\explorer /e,/root,%~d0\Audit File

Open in new window

0
 
LVL 21

Accepted Solution

by:
AmazingTech earned 2000 total points
ID: 23606479
If you don't want to open it with the tree folder view on the left then just call it like this.
%systemroot%\explorer %~d0\Audit File

Open in new window

0
 

Author Closing Comment

by:jonlake
ID: 31545330
Fantastic!, now I can sleep!
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
When you receive another warning that your shared drive is almost full and you have asked your users to clean out old files again and again, here is a single command that may help. This command will place all the files that have not been used rec…
Screencast - Getting to Know the Pipeline
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month13 days, 12 hours left to enroll

755 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