30

When I am running the following inside batch....

set PATH='C:\Users\DEB\Downloads\10.1.1.0.4'
cd !PATH!

I get error "The filename, directory name, or volume label syntax is incorrect"

Update: There are the solutions that worked for me.

  • Don't use PATH as a var name
  • set it as "myPATH=C:\Users\DEB DAS\Downloads\10.1.1.0.4"
Debajyoti Das
  • 2,038
  • 4
  • 34
  • 66
  • 2
    that should be `cd %PATH%` and you need to enclose the value in double quotes `"` not single quotes. But I would strongly discourage you from using that variable name - it has a a very special meaning. –  Jul 16 '14 at 14:02

2 Answers2

21
set myPATH="C:\Users\DEB\Downloads\10.1.1.0.4"
cd %myPATH%
  • The single quotes do not indicate a string, they make it starts: 'C:\ instead of C:\ so

  • %name% is the usual syntax for expanding a variable, the !name! syntax needs to be enabled using the command setlocal ENABLEDELAYEDEXPANSION first, or by running the command prompt with CMD /V:ON.

  • Don't use PATH as your name, it is a system name that contains all the locations of executable programs. If you overwrite it, random bits of your script will stop working. If you intend to change it, you need to do set PATH=%PATH%;C:\Users\DEB\Downloads\10.1.1.0.4 to keep the current PATH content, and add something to the end.

TessellatingHeckler
  • 27,511
  • 4
  • 48
  • 87
  • 3
    +1 but the `!name!` syntax can be used anywhere after a `setlocal ENABLEDELAYEDEXPANSION` and not just within loops. – foxidrive Jul 16 '14 at 14:19
  • @foxidrive so it can. I tested that at the command prompt and it didn't work, so I assumed it couldn't. But I've retried it in a batch file, and yes in that context it does work. I'll update my post - thanks. – TessellatingHeckler Jul 16 '14 at 14:43
0

In my case, if I use cmd to run batch file, and the batch file path is not correct show this error, for example users>E:\TEST"E:\TEST.bat error, users>E:\TEST.bat works. after check my path it's fixed.

yu yang Jian
  • 6,680
  • 7
  • 55
  • 80