syntax for batch file

G

geotso

I hope this is the right ng to post my question. If not, please redirect me
accordingly!

Well,
I have a myDir.bat file with just one line, like this:
dir %1:\%2

which works fine, when I type in a cmd window something like this:
myDir E *.mp3

However, sometimes I forget to add the two parameters, so I get an error
"... syntax is incorrect".
So, can you please tell me, how to make it check if the parameters are
there, and prompt me to write them down if they're not?

Furthermore, how to make it ask me if I want to use some switches of the dir
command (e.g. /a/s and/or /o/b/p etc.)?
 
C

Chirag

For the first part, the following batch file should do fine:

---
@echo off
if "%1"=="" (
echo "Invalid arguments. Usage: myDir <drive> <filter>"
exit /b 1
)
if "%2"=="" (
echo "Invalid arguments. Usage: myDir <drive> <filter>"
exit /b 2
)
dir %1:%2
---

- Chirag

PowerShow - View multiple PowerPoint slide shows simultaneously
http://officeone.mvps.org/powershow/powershow.html
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top