批处理文件在var中读取并回写 [英] Batch file read in var and write back

查看:63
本文介绍了批处理文件在var中读取并回写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次关闭或重新启动计算机时,我都需要计数.因此,我相信我可以通过将批处理文件添加到开始菜单来执行此操作.因此,每次您打开PC时,它将运行.它运行时应该

I need to count every time a computer is turn off or restarted. Thus I believe i can do this with a batch file by adding it to the start menu. Thus everytime you turn on PC it will run. When it runs it should

open c:\count.txt
read in the value on that text file
add 1 to it
write the value to the text file
exit.

但是我没有太多使用批处理文件,也无法弄清楚如何从文本文件中读取数字.

but I have not used batch files much and could not figure out how to read in the number from the text file.

推荐答案

根据您的想法(更新文件中的计数器):

based on your idea (updating a counter in a file):

rem open c:\count.txt
rem read in the value on that text file
set /p count=<c:\count.txt
rem add 1 to it
set /a count+=1
rem write the value to the text file
>c:\count.txt echo.%count%
rem exit.
exit

注意:注意,请选择用户具有写权限的路径.( C:\ 在没有特权的情况下可能无法工作)

Notice: Take care, that you choose a path the user has write access to. (C:\ may not work without privileges)

这篇关于批处理文件在var中读取并回写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆