批处理脚本将%% var移动到字符串变量

时间:2013-05-17 16:55:28

标签: batch-file

我正在尝试读取具有文件路径的文件print.txt

示例:C:\Documents and Settings\Administrator\My Documents\My Pictures\a1.jpg

它已成功读取,但当我尝试将其移动到文件名var时,它没有获得任何值。回声打印为'filename is: filename

FOR /f "tokens=*" %%s in (print.txt) do ( 
Set filename=" " %%s " "
echo.filename is: %filename
 )

1 个答案:

答案 0 :(得分:0)

试试这个: -

@echo off

SETLOCAL ENABLEDELAYEDEXPANSION
FOR /f "tokens=* delims=" %%s in (print.lst) do ( 
echo %%s
Set filename=%%s
echo filename is: "!filename!"
)

更新2

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
FOR /f "tokens=* delims=" %%s in (print.lst) do ( 
echo %%s
Set filename=%%s
echo filename is: "!filename!"
For %%A in (!filename!) do ( 
 Set Folder=%%~dpA 
 Set Name=%%~nxA 
 echo.Folder is: !Folder! 
 )
)