|
wjgyz740526
中级用户
  
积分 203
发帖 44
注册 2003-8-14
状态 离线
|
『楼 主』:
怎样把txt中的数值读出来并赋值给变量?
使用 LLM 解释/回答一下
cmd里怎样才能把一个txt文件中的数字读出来并赋值给变量?
求教,谢谢
How can I read the numbers from a txt file in cmd and assign them to variables?
Seeking advice, thank you
|
|
2007-3-22 00:47 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
这要取决于你的TXT文件的格式。
This depends on the format of your TXT file.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2007-3-22 02:10 |
|
|
wjgyz740526
中级用户
  
积分 203
发帖 44
注册 2003-8-14
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
怎么讲?
这个txt文件中只有一行数字
How to say?
There is only one line of numbers in this txt file
|
|
2007-3-22 02:11 |
|
|
lianjiang2004
金牌会员
     
积分 3946
发帖 1884
注册 2006-1-20
状态 离线
|
|
2007-3-22 03:57 |
|
|
wjgyz740526
中级用户
  
积分 203
发帖 44
注册 2003-8-14
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
我是想让cmd判断日期并在指定日期之后执行特定命令。
我的cmd在第一次运行时会判断是否存在tmp.txt,没有的话就把当前日期生成一个数字(比如20070320)保存在这个tmp.txt文件中,然后每一次运行cmd时判断是否过了一定日期(比如15天),大于15天就提示”XXXXX!“,我的代码如下
@Echo Off
set tm1=%date:~0,4%
set tm2=%date:~5,2%
set tm3=%date:~8,2%
set /a number=%tm1%*365+%tm2%*30+%tm3%
if not exist %windir%:\tmp.txt echo %number%>%windir%:\tmp.txt & goto end
goto begin
:begin
if .....这里涉及到怎样把txt中的数值读出来并且同当前日期转换后的number相比较,不会了
:end
请教达人,多谢
I want to let cmd judge the date and execute a specific command after the specified date.
My cmd will judge whether tmp.txt exists when it runs for the first time. If not, it will generate a number (such as 20070320) of the current date and save it in this tmp.txt file. Then every time cmd runs, it will judge whether a certain date (such as 15 days) has passed. If it is greater than 15 days, it will prompt "XXXXX!". My code is as follows
@Echo Off
set tm1=%date:~0,4%
set tm2=%date:~5,2%
set tm3=%date:~8,2%
set /a number=%tm1%*365+%tm2%*30+%tm3%
if not exist %windir%:\tmp.txt echo %number%>%windir%:\tmp.txt & goto end
goto begin
:begin
if .....Here it involves how to read the value in the txt and compare it with the number converted from the current date, I don't know.
:end
Ask the expert, thank you
|
|
2007-3-22 04:08 |
|
|
wjgyz740526
中级用户
  
积分 203
发帖 44
注册 2003-8-14
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
顶一下,期待中......
Give it a bump, looking forward to it......
|
|
2007-3-22 05:53 |
|
|
wjgyz740526
中级用户
  
积分 203
发帖 44
注册 2003-8-14
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
或者有别的办法能实现这个目的也行啊
Or there are other ways to achieve this purpose, that's fine too
|
|
2007-3-22 23:44 |
|
|
vkill
金牌会员
     
积分 4103
发帖 1744
注册 2006-1-20 来自 甘肃.临泽
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
>txt
set/p
or
for ... do (set ...)
>txt
set/p
or
for ... do (set ...)
|
|
2007-3-23 00:47 |
|
|
tianlijian
初级用户
 
积分 120
发帖 45
注册 2007-3-13
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
for /f "usebackq tokens=*" %i in ("%windir%\tem.txt") do ..
可以用这个方式把txt上的数读出来。
for /f "usebackq tokens=*" %i in ("%windir%\tem.txt") do ..
You can use this method to read the numbers from the txt.
|

test |
|
2007-3-23 01:37 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
|
2007-3-23 01:49 |
|
|
wjgyz740526
中级用户
  
积分 203
发帖 44
注册 2003-8-14
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
多谢,但是能讲讲什么意思吗?
set/p St=<tmp.txt 这一句
Thanks, but can you explain what it means?
set/p St=<tmp.txt This line
|
|
2007-3-24 00:52 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 12 楼』:
使用 LLM 解释/回答一下
把tmp.txt文件的第一行赋值给St变量。
Assign the first line of the tmp.txt file to the St variable.
|
|
2007-3-24 01:05 |
|
|
wjgyz740526
中级用户
  
积分 203
发帖 44
注册 2003-8-14
状态 离线
|
『第 13 楼』:
使用 LLM 解释/回答一下
谢谢楼上的兄弟!!!但是我翻遍set的帮助文档也找不到这个用法啊
Thanks to the brother upstairs!!! But I have ransacked the help documentation of set and can't find this usage.
|
|
2007-3-24 01:34 |
|
|
wjgyz740526
中级用户
  
积分 203
发帖 44
注册 2003-8-14
状态 离线
|
『第 14 楼』:
使用 LLM 解释/回答一下
我现在的代码,希望给有需要的兄弟一些帮助:
@Echo Off
set tm1=%date:~0,4%
set tm2=%date:~5,2%
set tm3=%date:~8,2%
set /a number=%tm1%*365+%tm2%*30+%tm3%
if not exist c:\tmp.txt echo %number%>c:\tmp.txt & exit
goto begin
:begin
set /p St=<c:\tmp.txt
set /a number2=%number%-%St%
if %number2% gtr 15 echo 你的使用期限已过15天& pause & exit
echo 您还在使用期,请继续使用
pause & exit
I'm currently sharing my code to offer some help to brothers in need:
@Echo Off
set tm1=%date:~0,4%
set tm2=%date:~5,2%
set tm3=%date:~8,2%
set /a number=%tm1%*365+%tm2%*30+%tm3%
if not exist c:\tmp.txt echo %number%>c:\tmp.txt & exit
goto begin
:begin
set /p St=<c:\tmp.txt
set /a number2=%number%-%St%
if %number2% gtr 15 echo 你的使用期限已过15天& pause & exit
echo 您还在使用期,请继续使用
pause & exit
|
|
2007-3-24 01:36 |
|
|
lxmxn
版主
       
积分 11386
发帖 4938
注册 2006-7-23
状态 离线
|
『第 15 楼』:
使用 LLM 解释/回答一下
Originally posted by wjgyz740526 at 2007-3-23 12:34:
谢谢楼上的兄弟!!!但是我翻遍set的帮助文档也找不到这个用法啊
很多用法都是人摸索出来的,帮助里面可能没有。
Originally posted by wjgyz740526 at 2007-3-23 12:34:
Thank you, brother above!!! But I have ransacked the help documentation of set and can't find this usage.
Many usages are explored by people, and it may not be in the help.
|
|
2007-3-24 03:11 |
|