我创建了一个用于存储日志信息的批处理文件,因此,假设您输入用户名并通过,它已加密并存储在文本文件中,效果很好,文本以这种格式存储:
xewiofjeoijfe
casowc43pcj89
依此类推,我只是在上面几行中使用了随机文本作为示例,因此每行新文本都添加到了文本文件的底部,我想做的是每次添加一行,并添加一个数字或名称和数字,如下所示:
username1 fewfuhvruivhriuvew
username2 erwve9p8rvejp9
username3 vj39gew4tg000904t3[0g9i40
我怎样才能做到这一点?
如果我了解您要执行的操作,则应该关闭此操作:
@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%"
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句