Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
2  
If you have @echo off you don't need to repeat the @ each time. –  Dennis Williamson Sep 16 '10 at 10:43

2 Answers 2

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
1  
For the MS docs see here: technet.microsoft.com/en-us/library/cc754335(WS.10).aspx –  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 255.255.255.0 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

 
discard

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.