我有一个批处理脚本,它应该解析文件名和时间戳的文件。
:MAIN
SETLOCAL EnableDelayedExpansion
FOR /F "tokens=1,2,4 skip=7" %%A in (C:\list_of_psa_files.txt) DO
@echo %%A %%B %%C
exit
文件C:\ list_of_psa_files.txt中包含以下数据
Volume in drive C is Windows XP 6.6
Volume Serial Number is AC12-84AA
Directory of C:\Test
10/05/2011 03:17 PM <DIR> .
10/05/2011 03:17 PM <DIR> ..
10/05/2011 01:21 PM 4,393 1-16332-1008261.psa
10/05/2011 01:21 PM 4,863 1-16332-1011698.psa
10/05/2011 01:21 PM 4,793 1-16332-1023151.psa
10/05/2011 01:21 PM 4,916 1-16332-1035695.psa
10/05/2011 01:21 PM 4,524 1-16332-1037029.psa
10/05/2011 01:21 PM 4,235 1-16332-1049340.psa
10/05/2011 01:21 PM 3,135 1-16332-1049926.psa
10/05/2011 01:21 PM 4,657 1-16332-1054756.psa
但是,当我运行我的脚本时,它失败并显示消息无效语法。有人可以帮我弄清楚我哪里出错了。
我要做的就是获取日期,时间和文件名,而不将扩展名写入旧文件中的新文件。
感谢您的时间 - 感谢它。
桑德斯。
答案 0 :(得分:2)
如果确实将echo
放在一个单独的行上(并且它不是编辑过程的假象),则不能这样做。您需要使用一行或:
FOR /F "tokens=1,2,4 skip=7" %%A in (C:\list_of_psa_files.txt) DO (
@echo %%A %%B %%C
)
当我创建您显示的文件和脚本时,我得到:
The syntax of the command is incorrect.
当我将其更改为我建议的变体时,它会输出:
10/05/2011 01:21 4,393
10/05/2011 01:21 4,863
10/05/2011 01:21 4,793
10/05/2011 01:21 4,916
10/05/2011 01:21 4,524
10/05/2011 01:21 4,235
10/05/2011 01:21 3,135
10/05/2011 01:21 4,657
正如所料。当您在一行上执行相同的输出时显示:
FOR /F "tokens=1,2,4 skip=7" %%A in (C:\list_of_psa_files.txt) DO @echo %%A %%B %%C