我有一组文本文件(log0.txt,log1.txt等),我想将其转换为其他格式。但是,每个文件的最后一行是不完整的,所以我想写一个批处理命令,它将删除每个文件的最后一行。在迭代文本文件上运行批处理命令
将军命令我工作是这样的:
@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
rem Count the lines in file
set /a count=-1
for /F %%a in (log0.txt) DO set /a count=!count!+1
rem Create empty temp file
copy /y NUL temp.txt >NUL
rem Copy all but last line
for /F %%a in (log0.txt) DO (
IF /I !count! GTR 0 (
echo %%a >>temp.txt
set /a count=!count!-1
)
)
rem overwrite original file, delete temp file
copy /y temp.txt log0.txt >NUL
del temp.txt
rem This for testing
type log0.txt
而不必复制并粘贴此为每个文本文件的,是那里的批处理命令对所有我的文字的操作方式文件?
你的循环中的想法非常好 – jeb
@jeb:谢谢jeb! '':-) – Aacini