Forum Discussion

pinefieldgene's avatar
pinefieldgene
Copper Contributor
Sep 30, 2023
Solved

How include space in file path on PS command line?

Hi I want get filesize that include space in file path. I try that failed.     PS E:\> $size = [math]::Round($(Get-ChildItem "E:\MyDocuments\!Onedrive\OneDrive - Specified Nonprofit Organizatio...
  • LainRobertson's avatar
    Sep 30, 2023

    pinefieldgene 

     

    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

Resources