Anders
Anders

Reputation: 15397

Batch file concatenate command line argument

As an example, I created a batch file named concatenate.bat:

@echo off
set foo=%1\bar
echo %foo%

When I run concatenate.bat "C:\somewhere\with spaces"

I want foo to output: "C:\somewhere\with spaces\bar"

But instead I get: "C:\somewhere\with spaces"\bar


I also tried: set "foo=%1\bar"

Which outputs: "C:\somewhere\with spaces"\bar


What's the correct way to do this?

Upvotes: 5

Views: 11428

Answers (1)

Bali C
Bali C

Reputation: 31231

@echo off
set foo="%~1\bar"
echo %foo%

Upvotes: 10

Related Questions