中国DOS联盟

-- 联合DOS 推动DOS 发展DOS --

联盟域名:www.cn-dos.net 论坛域名:www.cn-dos.net/forum
DOS,代表着自由开放与发展,我们努力起来,学习FreeDOS和Linux的自由开放与GNU精神,共同创造和发展美好的自由与GNU GPL世界吧!

中国DOS联盟论坛
现在时间是 2026-06-19 20:45
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [已結]請問For /F 要分析的檔案,路徑有空格該如何? 查看 783 回复 3
楼 主 [已結]請問For /F 要分析的檔案,路徑有空格該如何? 发表于 2008-07-19 21:30 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★★
积分 144
发帖 65
注册 2008-03-20 20:03
18年会员
UID 113522
性别 男
来自 Taiwan
状态 离线
請問若For /F 要分析的檔案路徑中有空白的話要怎麼處理
因為若把路徑加上 " " 就變成分析字串了
不加上 " " 會找不到檔案
請幫幫忙 謝謝!!

執行路徑為:

\\127.0.0.1\新資料夾\asdf 123\qwer 456



setlocal enabledelayedexpansion

echo.
SET xxxxx=%~dp0
set source=%xxxxx:~0,-1%
echo Source Path
echo %source%
pause


for /f "eol=# tokens=1,2,3* delims=," %%i in ( %source%\DisplayDB.csv ) do (
set D1=%%i
set D2=%%j
set D3=%%k
"%source%\devcon" find pci\* | find /i "%%i" && goto findOK
)

:findOK

echo %D1:~0,8%^&%D1:~-9%
echo %D2%
echo %D3%

pause



DisplayDB.csv 內容

VEN_1002&DEV_9585,ATI Radeon HD 500 PRO,D:\ReStore\Desktop\InstallPubDriver\2-Display\ATI\2600PRo\5Detup.exe
VEN_1002&DEV_9581,ATI Radeon HD 100 PRO,D:\ReStore\Desktop\InstallPubDriver\2-Display\ATI\2600PRo\1Setup.exe
VEN_1002&DEV_9589,ATI Radeon HD 900 PRO,D:\ReStore\Desktop\InstallPubDriver\2-Display\ATI\2600PRo\9Setup.exe


結果:
C:\WINDOWS>setlocal enabledelayedexpansion

C:\WINDOWS>echo.


C:\WINDOWS>SET xxxxx=\\127.0.0.1\新資料夾\asdf 123\qwer 456\

C:\WINDOWS>set source=\\127.0.0.1\新資料夾\asdf 123\qwer 456

C:\WINDOWS>echo Source Path
Source Path

C:\WINDOWS>echo \\127.0.0.1\新資料夾\asdf 123\qwer 456
\\127.0.0.1\新資料夾\asdf 123\qwer 456

C:\WINDOWS>pause
請按任意鍵繼續 . . .

C:\WINDOWS>for /F "eol=# tokens=1,2,3* delims=," %i in (\\127.0.0.1\新資料夾\asdf 123\qwer 456\DisplayDB.csv) do (
set D1=%i
set D2=%j
set D3=%k
"\\127.0.0.1\新資料夾\asdf 123\qwer 456\devcon" find pci\* | find /i "%i" && goto findOK
)
系統找不到檔案 \\127.0.0.1\新資料夾\asdf。

C:\WINDOWS>echo ~0,8D1:~-9
~0,8D1:~-9

C:\WINDOWS>echo
ECHO 已啟動。

C:\WINDOWS>echo
ECHO 已啟動。

C:\WINDOWS>pause


[ Last edited by XZ on 2008-7-19 at 11:47 PM ]
2 发表于 2008-07-19 21:50 ·  中国 江苏 苏州 电信
初级用户
★★
积分 195
发帖 93
注册 2006-10-28 08:20
19年会员
UID 68626
性别 男
状态 离线
for /f "eol=# tokens=1,2,3* delims=, usebackq" %%i in ( "%source%\DisplayDB.csv") do (
...........
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
XZ +1 2008-07-19 23:47
3 发表于 2008-07-19 22:10 ·  中国 重庆 九龙坡区 电信
版主
★★★★★
积分 9,023
发帖 5,017
注册 2007-05-31 19:39
19年会员
UID 89899
性别 男
状态 离线
for /?
usebackq - specifies that the new semantics are in force,
where a back quoted string is executed as a
command and a single quoted string is a
literal string command and allows the use of
double quotes to quote file names in
filenameset.
本帖最近评分记录 (共 1 条) 点击查看详情
评分人分数时间
XZ +1 2008-07-19 23:47
4 发表于 2008-07-19 23:46 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
★★
积分 144
发帖 65
注册 2008-03-20 20:03
18年会员
UID 113522
性别 男
来自 Taiwan
状态 离线
感謝..兩位
可以了..原來可以這樣用
不過繁中的解釋還真的比英文還難懂^^"

補上 For /? 繁中說明

usebackq - 指定新語義開始作用。
其中反括號的字串會被當作命令來執行,
而單引號字串是純文字字串。
此外還允許使用雙引號來
引用在 filenameset 內
的檔名。
论坛跳转: