至少这个领域的人在很大程度上是建设性的 - 围绕而不是系统地投票反对/删除/关闭不喜欢的问题和答案。
这是我的贡献,FWIW:
原始问题,尾随分号:
@echo off
SETLOCAL
ECHO.== file_list.txt ==========
TYPE file_list.txt
set v_file_list="file_list.txt"
ECHO.== batch run ==========
FOR /F "usebackqdelims=" %%A IN (%v_file_list%) DO (
SET filename=%%A
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%s IN (!filename!) DO (endlocal&ECHO %%s %%~zs)
)
ECHO.== actual DIR list ==========
DIR /a-d "u:\users\ab cd\ak"
运行结果:
== file_list.txt ==========
"u:\users\ab cd\ak\ak_ppf.pdf";
"u:\users\ab cd\ak\ak_ppf.jpg";
"u:\users\ab cd\ak\dl page 1.jpg";
"u:\users\ab cd\ak\dl page 2.jpg";
"u:\users\ab cd\ak\dl page 3.jpg";
"u:\users\ab cd\ak\dl page;4.jpg;";
"u:\users\ab cd\ak\dl page;4.jpg";
"u:\users\ab cd\ak\dl!page;4.jpg;";
"u:\users\ab cd\ak\dl%page%;4.jpg;";
"u:\users\ab cd\ak\dl!pag!e;4.jpg;";
== batch run ==========
"u:\users\ab cd\ak\ak_ppf.pdf" 21031
"u:\users\ab cd\ak\ak_ppf.jpg" 428
"u:\users\ab cd\ak\dl page 1.jpg" 54338
"u:\users\ab cd\ak\dl page 2.jpg" 83344
"u:\users\ab cd\ak\dl page 3.jpg" 14036
"u:\users\ab cd\ak\dl page;4.jpg;" 22498
"u:\users\ab cd\ak\dl page;4.jpg" 55506
"u:\users\ab cd\ak\dl!page;4.jpg;" 4007
"u:\users\ab cd\ak\dl%page%;4.jpg;" 5310
"u:\users\ab cd\ak\dl!pag!e;4.jpg;" 4693
== actual DIR list ==========
Volume in drive U has no label.
Volume Serial Number is 0466-0000
Directory of u:\users\ab cd\ak
10/04/2013 20:25 21,031 ak_ppf.pdf
10/04/2013 20:25 428 ak_ppf.jpg
10/04/2013 20:25 54,338 dl page 1.jpg
10/04/2013 20:26 83,344 dl page 2.jpg
10/04/2013 20:26 14,036 dl page 3.jpg
10/04/2013 20:41 22,498 dl page;4.jpg;
10/04/2013 20:40 55,506 dl page;4.jpg
10/04/2013 20:49 4,007 dl!page;4.jpg;
10/04/2013 20:50 5,310 dl%page%;4.jpg;
10/04/2013 21:31 4,693 dl!pag!e;4.jpg;
10 File(s) 265,191 bytes
0 Dir(s) 2,146,500,608 bytes free
一般示例,文本文件仅是文件名:
@echo off
SETLOCAL
ECHO.== file_list_raw.txt ==========
TYPE file_list_raw.txt
set v_file_list="file_list_raw.txt"
ECHO.== batch run ==========
FOR /F "usebackqdelims=" %%A IN (%v_file_list%) DO (
SET filename="%%~A"
SETLOCAL ENABLEDELAYEDEXPANSION
FOR %%s IN (!filename!) DO (endlocal&ECHO %%s %%~zs)
)
ECHO.== actual DIR list ==========
DIR /a-d "u:\users\ab cd\ak"
运行结果:
== file_list_raw.txt ==========
U:\users\ab cd\ak\ak_ppf.pdf
U:\users\ab cd\ak\ak_ppf.jpg
U:\users\ab cd\ak\dl page 1.jpg
U:\users\ab cd\ak\dl page 2.jpg
U:\users\ab cd\ak\dl page 3.jpg
U:\users\ab cd\ak\dl page;4.jpg;
U:\users\ab cd\ak\dl page;4.jpg
U:\users\ab cd\ak\dl!page;4.jpg;
U:\users\ab cd\ak\dl%page%;4.jpg;
U:\users\ab cd\ak\dl!pag!e;4.jpg;
"U:\users\ab cd\ak\ak_ppf.pdf"
"U:\users\ab cd\ak\ak_ppf.jpg"
"U:\users\ab cd\ak\dl page 1.jpg"
"U:\users\ab cd\ak\dl page 2.jpg"
"U:\users\ab cd\ak\dl page 3.jpg"
"U:\users\ab cd\ak\dl page;4.jpg;"
"U:\users\ab cd\ak\dl page;4.jpg"
"U:\users\ab cd\ak\dl!page;4.jpg;"
"U:\users\ab cd\ak\dl%page%;4.jpg;"
"U:\users\ab cd\ak\dl!pag!e;4.jpg;"
== batch run ==========
"U:\users\ab cd\ak\ak_ppf.pdf" 21031
"U:\users\ab cd\ak\ak_ppf.jpg" 428
"U:\users\ab cd\ak\dl page 1.jpg" 54338
"U:\users\ab cd\ak\dl page 2.jpg" 83344
"U:\users\ab cd\ak\dl page 3.jpg" 14036
"U:\users\ab cd\ak\dl page;4.jpg;" 22498
"U:\users\ab cd\ak\dl page;4.jpg" 55506
"U:\users\ab cd\ak\dl!page;4.jpg;" 4007
"U:\users\ab cd\ak\dl%page%;4.jpg;" 5310
"U:\users\ab cd\ak\dl!pag!e;4.jpg;" 4693
"U:\users\ab cd\ak\ak_ppf.pdf" 21031
"U:\users\ab cd\ak\ak_ppf.jpg" 428
"U:\users\ab cd\ak\dl page 1.jpg" 54338
"U:\users\ab cd\ak\dl page 2.jpg" 83344
"U:\users\ab cd\ak\dl page 3.jpg" 14036
"U:\users\ab cd\ak\dl page;4.jpg;" 22498
"U:\users\ab cd\ak\dl page;4.jpg" 55506
"U:\users\ab cd\ak\dl!page;4.jpg;" 4007
"U:\users\ab cd\ak\dl%page%;4.jpg;" 5310
"U:\users\ab cd\ak\dl!pag!e;4.jpg;" 4693
== actual DIR list ==========
Volume in drive U has no label.
Volume Serial Number is 0466-0000
Directory of u:\users\ab cd\ak
10/04/2013 20:25 21,031 ak_ppf.pdf
10/04/2013 20:25 428 ak_ppf.jpg
10/04/2013 20:25 54,338 dl page 1.jpg
10/04/2013 20:26 83,344 dl page 2.jpg
10/04/2013 20:26 14,036 dl page 3.jpg
10/04/2013 20:41 22,498 dl page;4.jpg;
10/04/2013 20:40 55,506 dl page;4.jpg
10/04/2013 20:49 4,007 dl!page;4.jpg;
10/04/2013 20:50 5,310 dl%page%;4.jpg;
10/04/2013 21:31 4,693 dl!pag!e;4.jpg;
10 File(s) 265,191 bytes
0 Dir(s) 2,146,500,608 bytes free
该代码实际上与已经发布的代码和那些帖子中的评论没有太大区别。