|
XZ
初级用户
 
积分 144
发帖 65
注册 2008-3-20 来自 Taiwan
状态 离线
|
『楼 主』:
[已結]請問For /F 要分析的檔案,路徑有空格該如何?
請問若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 ]
|
|
2008-7-19 21:30 |
|
|
metoo
初级用户
 
积分 195
发帖 93
注册 2006-10-28
状态 离线
|
『第
2 楼』:
for /f "eol=# tokens=1,2,3* delims=, usebackq" %%i in ( "%source%\DisplayDB.csv") do (
...........
此帖被 +1 点积分 点击查看详情 评分人:【 XZ 】 | 分数: +1 | 时间:2008-7-19 23:47 |
|
|
|
2008-7-19 21:50 |
|
|
HAT
版主
       
积分 9023
发帖 5017
注册 2007-5-31
状态 离线
|
『第
3 楼』:
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-7-19 23:47 |
|
|

|
|
2008-7-19 22:10 |
|
|
XZ
初级用户
 
积分 144
发帖 65
注册 2008-3-20 来自 Taiwan
状态 离线
|
『第
4 楼』:
感謝..兩位
可以了..原來可以這樣用
不過繁中的解釋還真的比英文還難懂^^"
補上 For /? 繁中說明 usebackq - 指定新語義開始作用。
其中反括號的字串會被當作命令來執行,
而單引號字串是純文字字串。
此外還允許使用雙引號來
引用在 filenameset 內
的檔名。
|
|
2008-7-19 23:46 |
|