BATCH中FOR循环的变量IN语句内部的空间

时间:2018-10-28 08:54:34

标签: batch-file

我想检索并使用给定.txt文件的元素(令牌)来基于该文件进行操作:

set txtsource=D:\some path with spaces\source.txt
set picsdir=D:\other path with spaces

for /f "tokens=1,2 delims=/" %%i in (%txtsource%) do (echo "%picsdir%\%%i" "%picsdir%\%%j")

问题:这给出了“系统找不到文件D:\ some。”

第二次尝试:

set txtsource=D:\some path with spaces\source.txt
set picsdir=D:\other path with spaces

for /f "tokens=1,2 delims=/" %%i in ("%txtsource%") do (echo "%picsdir%\%%i" "%picsdir%\%%j")

问题:此操作无法正确打开/读取txtsource文件,从而回显了路径,而不是echo source.txt中的内容。

第三次尝试:

set txtsource=D:\some path with spaces\source.txt
set picsdir=D:\other path with spaces

for /f "tokens=1,2 delims=/" %%i in ('%txtsource%') do (echo "%picsdir%\%%i" "%picsdir%\%%j")

问题:这说“'D:\ some'无法识别(...)”。

任何想法如何使这项工作有效吗?

1 个答案:

答案 0 :(得分:0)

所有关于报价!

 declare @userType SMALLINT
    if (@userType = 1)

    "Select * from singleTable where UserType = 1 and UserName = '" + userName.Text + "'"
    else if (@userType = 2) Select * from singleTable where UserType = 2 and UserName = '" + userName.Text + "'
    else if (@userType = 3) select * from singleTable where UserType = 3 and UserName = '" + userName.Text + "'