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.