When working with Robocopy's /log parameter, many developers encounter path-related errors because Windows file systems allow spaces in directory and file names. The common mistake is improper escaping or quoting of paths containing spaces.
The proper way to specify log file paths with spaces is to:
robocopy "source" "destination" /log:"C:\\Path with spaces\\logfile.txt"
Key requirements:
- Use double quotes around the entire path
- Escape backslashes with another backslash
- Place the /log parameter after source/destination paths
Working example with network paths:
robocopy "D:\\Project Files" "\\\\server\\Backup\\Project Backup" /mir
/log:"D:\\Backup Logs\\project_mirror_log.txt"
Complex path example with date stamps:
robocopy "C:\\User Data" "E:\\Archives" /copyall /zb
/log:"C:\\Admin\\Logs\\2023-11-15 User Data Transfer.log"
For automated scripts, consider these patterns:
:: Dynamic log filename with timestamp
set logfile="C:\\Robocopy Logs\\%DATE:~-4,4%%DATE:~-10,2%%DATE:~-7,2%_Backup.log"
robocopy "D:\\Data" "F:\\Backup" /mir /log:%logfile%
- Mixing straight and curly quotes (always use straight quotes)
- Forgetting to escape backslashes in batch files
- Placing the /log parameter before source/destination paths
- Using relative paths when absolute paths are required
When working with Robocopy (Robust File Copy) in Windows environments, path handling - especially with spaces - can sometimes trip up even experienced sysadmins. The utility's parameter parsing has some unique behaviors that aren't always intuitive.
The proper way to specify a log file path containing spaces in Robocopy is:
robocopy "C:\source folder" "D:\destination folder" /mir /log:"C:\path with spaces\robocopy.log"
Key observations from testing:
- Both the source/destination paths AND the log parameter need proper quoting
- The quotes must be straight quotes (") not curly quotes
- The space after /log: must be preserved before the opening quote
Here are some invalid patterns that will fail:
# Missing space after /log:
/log:"path" → ERROR
# Using single quotes
/log:'path' → ERROR
# Nested quotes incorrectly
/log:""path"" → ERROR
For complex automation scenarios, consider these robust implementations:
Dynamic Log File Naming
@echo off
set LOGPATH="C:\Daily Logs\robocopy_%date:~10,4%-%date:~4,2%-%date:~7,2%.log"
robocopy "\\server\share" "D:\backups" /mir /log:%LOGPATH%
Error Handling in Scripts
$source = "C:\User Documents"
$dest = "D:\Archives\2023"
$logfile = "C:\Admin Tools\Logs\document_backup_$(Get-Date -Format 'yyyyMMdd').log"
robocopy $source $dest /mir /log:$logfile
if ($LASTEXITCODE -ge 8) {
Write-EventLog -LogName Application -Source "Robocopy" -EntryType Error -EventId 100 -Message "Backup failed with exit code $LASTEXITCODE"
}
The initial error message:
ERROR : Invalid Parameter #10 : "/log:x:\path to logs\12-15-11 01 file with spaces.txt"
typically indicates either:
- A missing space between /log: and the opening quote
- Hidden special characters in the path (like tab characters)
- Incorrect quote characters copied from rich text
- Consider using 8.3 short names for maximum compatibility:
/log:C:\PROGRA~1\LOGS\ROBO~1.LOG
- For scheduled tasks: store logs in paths without spaces to simplify troubleshooting
- Implement log rotation by including timestamps in filenames
- Always validate exit codes (0-7 are success codes in Robocopy)