0

我有一个批处理脚本来读取文本文件。如果文件名不包含特殊字符,它工作正常,但如果文件名包含特殊字符,它会失败。

前文件名:localhost_access_log.2013-03-08

代码:

for /f "skip=%* tokens=*" %%b in (Y:\Program Files\Apache Software Foundation\Tomcat 7.0\logs\localhost_access_log.2013-03-08.txt) do (
    echo "Data Copied"
)

请帮助我如何阅读这些文件。

4

1 回答 1

1

在命令行中键入help for以获取有关 for 命令的文档(我承认这很难阅读),然后您将其隐藏在大约一半的位置:

For file names that contain spaces, you need to quote the filenames with
double quotes.  In order to use double quotes in this manner, you also
need to use the usebackq option, otherwise the double quotes will be
interpreted as defining a literal string to parse.

因此,您的代码应更改为:

for /f "usebackq skip=%* tokens=*" %%b in ("Y:\Program Files\Apache Software Foundation\Tomcat 7.0\logs\localhost_access_log.2013-03-08.txt") do (
    echo "Data Copied"
)
于 2013-03-08T14:33:27.053 回答