Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

With my .cmd script, all I am doing is creating a new file, setting a location for the file, naming it and adding an extension. I need one last bit to finish this.

If nothing is entered in fileLocation then I want it to be place on the desktop. How can I do this?

@echo off
@echo --- Create A New File ---
@echo -
@echo Choose File Desination.
set /p fileLocation=@
@echo -
@echo What do you want to call your new file?
set /p fileName=@
@echo -
@echo Almost Done! What is the files extension?
set /p extension=@
echo -
copy NUL "%fileLocation%/%fileName%.%extension%"
share|improve this question
If you have @echo off you don't need to repeat the @ each time. – Dennis Williamson Sep 16 '10 at 10:43

See Microsoft DOS if command or this.

To test for the existence of a parameter use empty brackets like this

IF [%fileLocation%]==[] ECHO Value Missing
share|improve this answer
I'm a noob at this, can you explain how to insert it in the command pleasse? – Omnix Sep 16 '10 at 6:36
For the MS docs see here: – Richard Sep 16 '10 at 7:43

IF [condition] [command]

  if %1==dhcp (
    netsh int ip set address name="Local Area Connection" source=dhcp
    netsh int ip set dns "Local Area Connection" dhcp
  ) else (
    netsh int ip set address name="Local Area Connection" source=static 192.168.%1.%2 192.168.%1.1 1
    netsh int ip set dns "Local Area Connection" static 192.168.%1.1

This will taken the first and second parameters passed to the script file (script.bat dhcp or script.bat 14 25) and set the IP to either DHCP or 192.168.[14].[25] - %1 and %2 respectively

Note: I've never had good luck nesting IFs within a batch script, i usually will call another batch like a function if i need to do nesting, or use VBS.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.