Skip to content

/errors/cmd/the-filename-directory-name-or-volume-label-syntax-is-incorrect

The filename, directory name, or volume label syntax is incorrect.

verified onenvironmentlocal · windows 10.0.26200 arm64 · GNU bash 5.3.15 (Git Bash)updated
tool
Command Prompt (cmd)
exit code
1
versions
Windows 10, Windows 11, Windows Server 2016+
os
windows

The filename, directory name, or volume label syntax is incorrect. is Windows system error 123 (ERROR_INVALID_NAME). The path is not a valid Windows name at all, so Windows does not even look for it. File and folder names cannot contain < > : " / \ | ? *; a colon is only allowed after the drive letter. Print the expanded path and remove the character that does not belong.

Reproduce it

cmd
mkdir "build<1>" 2>&1
mkdir "logs|old" 2>&1
mkdir "logs-2026-10-21"
dir /b /ad logs*

Output

The filename, directory name, or volume label syntax is incorrect.
The filename, directory name, or volume label syntax is incorrect.
logs-2026-10-21

Common sources of bad names

SourceExampleFix
%DATE% or %TIME% in a namebackup_%TIME%.zip contains colonsuse a sortable date without separators, see below
Pasted from a browser or Explorerfile:///C:/data or a smart quotepaste plain text, remove the prefix
Variable with quotes, quoted againset "DIR="C:\x"", then "%DIR%\out"store values without quotes, quote at use
Wrong drive syntaxC;\data, C:dataC:\data

A date-based name that is valid on every locale:

cmd
for /f %%d in ('powershell -NoProfile -Command "Get-Date -Date 2026-10-21 -Format yyyy-MM-dd"') do set "STAMP=%%d"
mkdir "backup-%STAMP%"
dir /b /ad backup-*

Output

backup-2026-10-21

In a real script, drop -Date 2026-10-21 to use today's date. %DATE% itself is not portable: its format follows the user's regional settings and usually contains /.

Sources