标题: [已結]請問For /F 要分析的檔案,路徑有空格該如何?
[打印本页]
作者: XZ
时间: 2008-7-19 21:30
标题: [已結]請問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 ]
作者: metoo
时间: 2008-7-19 21:50
for /f "eol=# tokens=1,2,3* delims=, usebackq" %%i in ( "%source%\DisplayDB.csv") do (
...........
作者: HAT
时间: 2008-7-19 22:10
for /?
Quote: |
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. |
|
作者: XZ
时间: 2008-7-19 23:46
感謝..兩位
可以了..原來可以這樣用
不過繁中的解釋還真的比英文還難懂^^"
補上 For /? 繁中說明
usebackq - 指定新語義開始作用。
其中反括號的字串會被當作命令來執行,
而單引號字串是純文字字串。
此外還允許使用雙引號來
引用在 filenameset 內
的檔名。