我创建了一个存储日志信息的批处理文件,所以假设你输入用户名并传递,它被加密并存储在一个文本文件中,效果很好,文本以这种格式存储:
xewiofjeoijfe
casowc43pcj89
依此类推,我只是在上面的行中使用随机文本作为示例,因此每个新的文本行都添加到文本文件的底部,我想要做的就是每一行添加一个新行的时间,添加一个数字或名称和数字,如下所示:
username1 fewfuhvruivhriuvew
username2 erwve9p8rvejp9
username3 vj39gew4tg000904t3[0g9i40
我怎样才能做到这一点?
答案 0 :(得分:2)
如果我明白你想要做什么,这应该是关闭的:
@echo off
set "LogFile=Test.txt"
if not exist "%LogFile%" type nul>"%LogFile%" & rem this line needed to create empty file if file does not exist
set "YourLoggedInfo=SomeInfoYouLogged" & rem this line will be replaced by what you are currently logging
rem below we will get number of existing lines and add 1
set /a LastLine=0
for /f "usebackq tokens=1 delims=:" %%a in (`findstr /n . "%LogFile%"`) do set /a LastLineNum=%%a
set /a LastLineNum+=1
rem replace %YourLoggedInfo% in the line below with what you are currently logging
echo(Username%LastLineNum% %YourLoggedInfo% >>"%LogFile%"