Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Batch PATH with Quotes

Tags:

batch-file

How can check if path has quotes or not, and add it if not have? I know i can make something like:

set /p path="My path "
"%path%"

But i have problems with quotes

C:\My folder --> "%path%" --> "C:\My folder" --> Good

If the user put a path with quotes

"C:\My folder" --> "%path%" --> ""C:\My folder"" --> Wrong

I can't use double quotes because the external command line i call not work and give me error. So how i can add "" only if not found in path? Thanks

like image 887
Terenz Avatar asked Apr 19 '13 14:04

Terenz


3 Answers

You can remove quote before using it, try:

set path=%path:"=%

path has not quote any more.

Example:

@echo off

set path="a b c"

set path=%path:"=%

echo %path%

Output

a b c
like image 63
masoud Avatar answered Nov 09 '22 04:11

masoud


  for /f "delims=" %%i in ("%var%") do set "var=%%~i"
  echo %var%

%var% has no double quotes around after the for loop.

Btw: you should not use cmd commands as batch variables (PATH).

like image 25
Endoro Avatar answered Nov 09 '22 04:11

Endoro


Can't test this as I'm writing from my phone, but can't you just assume there are double quotes and do a find & replace:

set path=%path:""="%
like image 1
lars-august Avatar answered Nov 09 '22 05:11

lars-august