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%"
link|improve this question

29% accept rate
1  
If you have @echo off you don't need to repeat the @ each time. – Dennis Williamson Sep 16 '10 at 10:43
feedback

2 Answers

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
link|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: technet.microsoft.com/en-us/library/cc754335(WS.10).aspx – Richard Sep 16 '10 at 7:43
feedback

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.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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