How to wrap filename with blanks inside?
Posted: 28 Feb 2024 07:10
In a DOS batch script I wrote a command to start a powershell command:
As long as the filename does not contain any blanks the command above works.
As soon as it contains blanks I have a problem. The following does not work:
Command prompt output shows me the following error:
At line:1 char:27
+ & {'D:\tmp\test args.ps1' 'D:\tmp\236 236.pdf'}
+ ~~~~~~~~~~~~~~~~~~~~
Unexpected token ''D:\tmp\236 236.pdf'' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
How else can I use a filename (and possibly path) with blanks inside?
Code: Select all
Powershell.exe -noprofile -noexit -command "& {D:\tmp\testargs.ps1 %args%}"
As soon as it contains blanks I have a problem. The following does not work:
Code: Select all
Powershell.exe -noprofile -noexit -command "& {'D:\tmp\test args.ps1' %args%}"
At line:1 char:27
+ & {'D:\tmp\test args.ps1' 'D:\tmp\236 236.pdf'}
+ ~~~~~~~~~~~~~~~~~~~~
Unexpected token ''D:\tmp\236 236.pdf'' in expression or statement.
+ CategoryInfo : ParserError: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : UnexpectedToken
How else can I use a filename (and possibly path) with blanks inside?