Categories: Windows Commands

The syntax of the command is incorrect

This is a common error we would encounter while working with windows command prompt. It means that there’s something wrong in the arguments passed on to the command. Reasons could be any of the below.

  • Not passing the right parameters to the command. For example, Rmdir command expects the directory name to be provided. Not adding this argument causes the error below.
    c:>rmdir
    The syntax of the command is incorrect.
  • Passing more arguments than the command accepts
    c:>move file1 file2 file3
    The syntax of the command is incorrect.

    Move command expects only two arguments, one for the actual file and the other for the destination file. Adding an extra argument causes the command to fail with the error.

  • This error can also occur even if we are passing the right number of arguments but the argument is not in the expected format. For example, ‘mkdir’ expects the directory path to be in the windows format like dir1dir2. If you specify the path in Linux format as in dir1/dir2, it causes the error.
    c:>mkdir dir1/dir2
    The syntax of the command is incorrect.

How to resolve the error

If you encounter this error, the next thing to do is to check the usage of the command and identify what’s wrong in the command you ran. You can refer articles on this websiste for understanding syntax and example use cases. All the articles for windows commands are listed here. Windows commands reference.

Also, we can find the usage of a command by running the command with an argument /?. For example to check the usage of shutdown command, you can find it as below.

shutdown /?

Please add to the comments below if you are not able to fix the issue. I would do my best to reply back with a solution.

Srini

View Comments

  • Hi,

    I was trying to execute the following command but keep seeing "The syntax of the command is incorrect" message. I checked and reference to the example from rename files en masse" and cannot find what is wrong...

    forfiles /M *.pdf /C "cmd /c rename @file \"@fname - post.pdf\""

    Can you help to advise? Thanks in advance.

    Regards
    KM

  • Looks like it works if you move @fname out of the quotes.

    forfiles /M *.pdf /C "cmd /c rename @file @fname\" - post.pdf\""
  • i need this to delete .zip files older than 7 days. im not sure what im doing wrong
    forfiles /m *.zip /c "cmd /c Del *.zip " /d -7

  • I have 5 folders with hundreds of photos, but all of them are converted to .chk.
    I want convert them back to JPEG by using Command prompt. When I come to this point
    "Then choose your folder CD " I get a message "The syntax of the command is incorrect".
    The 5 folders are named FOUND.001 ..........005. The files start from FILE0000.chk
    Please help me to solve this problem

  • manage-bde -unlock c: -rp

    I get told the syntax of the command is incorrect.
    I'm putting my bitlocker password in for the recovery password with the _ inbetween each set of 6 numbers. I tried it without dashes too.

  • It's sad that batch file don't give a good answer, which would help to debug them. I encountered also the same message recently. My code was something like this:

    > IF defined %TRUE% ( ...

    The problem here were the percent signs. So the correct way to write this was

    > IF defined TRUE ( ...

  • Hello everyone,

    I am having a syntax error when executing my forfiles command.

    My proposal is to develop a .bat script to everyday copy the last file backup from a folder to the one drive folder located in another drive "K"

    This is the command I am using

    forfiles /p D:\Micros\Database\Data\Backup\Archive\ /D +0 /C "cmd /c copy @file K:\OneDrive\OneDrive - Company Name Inc\Backups"

    My output result:

    The syntax of the command is incorrect.

    Thank you to all for your help!

  • Script:
    CALL c:\work\flatfilechk.cmd "%x1%","%x2%"

    The above line is working froml one cmd file, and the same I am trying from other cmd which is not working. I am getting the error like "the syntax of the command is incorrect?
    Please give some resolution for this.

Recent Posts

Add new user account from command line (CMD)

Adding users from command line is much easier than going through the UI. It saves…

4 years ago

Delete directory from command line [Rmdir]

Do you want to delete a directory from Windows command prompt(CMD)? This post explains how…

4 years ago

TaskKill: Kill process from command line (CMD)

We can kill a process from GUI using Task manager. If you want to do…

4 years ago

Kill Chrome from command line

Chrome is definitely the stable browser compared to other ones and it has been my…

4 years ago

Find windows OS version from command line

Windows has multiple command line utilities that can help find the version of the Windows…

4 years ago

How to check if Windows 32 or 64 bit?

There are multiple ways to check whether a Windows computer is running 32-bit OS or…

7 years ago