1

I tried to copy a file with robocopy, but the PowerShell gives me an error "MissingArgument":

robocopy D:\Enciclopedia` mia\Tutorial` FATTI` DA` ME\Internet\Google\Limitare` permessi` di` alcune` celle` o` colonne` o` righe` in` Google` Sheets C:\Users\Raffaele\Desktop Protect,` hide,` and` edit` sheets` -` Computer` (Proteggere,` limitare` permessi` di` alcune` celle` o` colonne` o` righe` in` Google` Sheets)` -` Docs` Editors` Help.pdf

File name:

Protect, hide, and edit sheets - Computer (Proteggere, limitare permessi di alcune celle o colonne o righe in Google Sheets) - Docs Editors Help.pdf

File path:

D:\Enciclopedia mia\Tutorial FATTI DA ME\Internet\Google\Limitare permessi di alcune celle o colonne o righe in Google Sheets

I used the same command on a different file, and it works perfectly:

robocopy C:\Users\Raffaele\Desktop\Rapida C:\Users\Raffaele\Desktop\a BULK` MIO.pdf

Could you tell me how can I overcome this problem please?

Theo
  • 57,719
  • 8
  • 24
  • 41
Gennaro Arguzzi
  • 769
  • 1
  • 14
  • 27
  • 2
    Try quoting the paths (`'C:\Users\Raffaele\Desktop\a BULK MIO.pdf'`) instead of adding all those backticks. (altough this first extremely long path and filename can cause trouble). Why such LOOOOOOOONG names anyway? – Theo Feb 21 '21 at 11:19

1 Answers1

1

It's worth heeding Theo's advice: enclosing your file names that contain spaces and other special characters either in single quotes ('...', for verbatim values) or double quotes ("...", if you need string interpolation) is the simplest solution.[1]

While escaping characters individually with `, without enclosing quoting does work, it's visually less obvious and, as in your case, it is easy to miss characters that need escaping:

In PowerShell ,, (, and ) are also metacharacters that require escaping in order to be interpreted verbatim, and you neglected to escape them.

Therefore, escape as follows, using Write-Output as an example command to demonstrate that the names are parsed correctly:

PS> Write-Output D:\Enciclopedia` mia\Tutorial` FATTI` DA` ME\Internet\Google\Limitare` permessi` di` alcune` celle` o` colonne` o` righe` in` Google` Sheets C:\Users\Raffaele\Desktop` Protect`,` hide`,` and` edit` sheets` -` Computer` `(Proteggere`,` limitare` permessi` di` alcune` celle` o` colonne` o` righe` in` Google` Sheets`)` -` Docs` Editors` Help.pdf

D:\Enciclopedia mia\Tutorial FATTI DA ME\Internet\Google\Limitare permessi di alcune celle o colonne o righe in Google Sheets
C:\Users\Raffaele\Desktop Protect, hide, and edit sheets - Computer (Proteggere, limitare permessi di alcune celle o colonne o righe in Google Sheets) - Docs Editors Help.pdf

List of metacharacters that require individual escaping in unquoted command arguments:

<space> ' " ` , ; ( ) { } | & < > @ #

Note:

  • Of these, < > @ # are only special at the start of an argument.
  • Situationally, . (dot) requires escaping too, namely if the argument can syntactically be interpreted as accessing a variable's property (e.g., Write-Output $env:computername.csv outputs nothing - see this answer).
  • If you want a $ to be treated verbatim rather than refer to a variable or subexpression, you must escape it too.
  • For a complete overview of how unquoted command arguments are parsed in PowerShell, see this answer.

[1] See the bottom section of this answer for an overview of PowerShell string literals in general, and this answer for the rules of string interpolation in so-called expandable strings ("..."), specifically.

mklement0
  • 382,024
  • 64
  • 607
  • 775