Forum Discussion
How include space in file path on PS command line?
- Sep 30, 2023
What is the exact error are you getting?
PowerShell has no issues with paths containing spaces, so with no error to refer to, I can't seen any issue.
I'd also point out that your final example isn't going to work. You can use double quotes or single quotes, but not both together as you have done in that example.
Double quotes are useful where you intend to use variables (and other special characters) inside of a string - as you have done with "$size MB", while single quotes are used where all PowerShell-specific special characters must be ignored.
What your second example is telling PowerShell to do is look for a single file in the current working directory that has an actual filename (not a path) of 'E:\MyDocuments\!Onedrive\OneDrive - Specified Nonprofit Organization Sample Japan\Sample.pdf', which isn't a valid filename.
Here's some examples of appropriate (first two commands) and inappropriate (final command) quote usage as well as a path containing spaces.
Cheers,
Lain
What is the exact error are you getting?
PowerShell has no issues with paths containing spaces, so with no error to refer to, I can't seen any issue.
I'd also point out that your final example isn't going to work. You can use double quotes or single quotes, but not both together as you have done in that example.
Double quotes are useful where you intend to use variables (and other special characters) inside of a string - as you have done with "$size MB", while single quotes are used where all PowerShell-specific special characters must be ignored.
What your second example is telling PowerShell to do is look for a single file in the current working directory that has an actual filename (not a path) of 'E:\MyDocuments\!Onedrive\OneDrive - Specified Nonprofit Organization Sample Japan\Sample.pdf', which isn't a valid filename.
Here's some examples of appropriate (first two commands) and inappropriate (final command) quote usage as well as a path containing spaces.
Cheers,
Lain
- pinefieldgeneOct 06, 2023Copper ContributorHello.
I have tried several times to get the file size even if the path contains spaces in the file.