We help IT Professionals succeed at work.

Browse CD using Batch File

jonlake
jonlake asked
on
Medium Priority
525 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.
Comment
Watch Question

Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
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
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
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

Author

Commented:
Hmmm, I was hoping to open the cd in explorer using the batch file.
Top Expert 2009

Commented:
Try it like this
%systemroot%\explorer /e,/root,%~d0

Open in new window

Author

Commented:
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
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
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
Steve KnightIT Consultancy
CERTIFIED EXPERT

Commented:
Try
start "Your CD description" "%~d0\Audit File"

Steve
Top Expert 2009

Commented:
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

Top Expert 2009
Commented:
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

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Fantastic!, now I can sleep!
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.