![]() |
China DOS Union-- Unite DOS · Advance DOS · Grow DOS --Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum |
| Guest | Log in | Register | Members | Search | China DOS Union |
|
中国DOS联盟论坛 The time now is 2026-08-03 21:29 |
48,038 topics / 350,123 posts / today 0 new / 48,251 members |
| DOS批处理 & 脚本技术(批处理室) » How to read the values in a txt file and assign them to variables? |
| Printable Version 2,078 / 19 |
| Floor1 wjgyz740526 | Posted 2007-03-22 00:47 |
| 中级用户 Posts 44 Credits 203 | |
|
How can I read the numbers from a txt file in cmd and assign them to variables?
Seeking advice, thank you |
|
| Floor2 Climbing | Posted 2007-03-22 02:10 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
This depends on the format of your TXT file.
|
|
| Floor3 wjgyz740526 | Posted 2007-03-22 02:11 |
| 中级用户 Posts 44 Credits 203 | |
|
How to say?
There is only one line of numbers in this txt file |
|
| Floor4 lianjiang2004 | Posted 2007-03-22 03:57 |
| 金牌会员 Posts 1,884 Credits 3,946 | |
|
For example.
It needs to be analyzed specifically for specific problems. |
|
| Floor5 wjgyz740526 | Posted 2007-03-22 04:08 |
| 中级用户 Posts 44 Credits 203 | |
|
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 |
|
| Floor6 wjgyz740526 | Posted 2007-03-22 05:53 |
| 中级用户 Posts 44 Credits 203 | |
|
Give it a bump, looking forward to it......
|
|
| Floor7 wjgyz740526 | Posted 2007-03-22 23:44 |
| 中级用户 Posts 44 Credits 203 | |
|
Or there are other ways to achieve this purpose, that's fine too
|
|
| Floor8 vkill | Posted 2007-03-23 00:47 |
| 金牌会员 Posts 1,744 Credits 4,103 From 甘肃.临泽 | |
|
>txt
set/p or for ... do (set ...) |
|
| Floor9 tianlijian | Posted 2007-03-23 01:37 |
| 初级用户 Posts 45 Credits 120 | |
|
You can use this method to read the numbers from the txt. |
|
| Floor10 lxmxn | Posted 2007-03-23 01:49 |
| 版主 Posts 4,938 Credits 11,386 | |
|
```
@echo off set/p St=<tmp.txt echo %St% pause&exit/b ``` |
|
| Floor11 wjgyz740526 | Posted 2007-03-24 00:52 |
| 中级用户 Posts 44 Credits 203 | |
|
Thanks, but can you explain what it means?
set/p St=<tmp.txt This line |
|
| Floor12 lxmxn | Posted 2007-03-24 01:05 |
| 版主 Posts 4,938 Credits 11,386 | |
|
Assign the first line of the tmp.txt file to the St variable.
|
|
| Floor13 wjgyz740526 | Posted 2007-03-24 01:34 |
| 中级用户 Posts 44 Credits 203 | |
|
Thanks to the brother upstairs!!! But I have ransacked the help documentation of set and can't find this usage.
|
|
| Floor14 wjgyz740526 | Posted 2007-03-24 01:36 |
| 中级用户 Posts 44 Credits 203 | |
|
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 |
|
| Floor15 lxmxn | Posted 2007-03-24 03:11 |
| 版主 Posts 4,938 Credits 11,386 | |
Originally posted by wjgyz740526 at 2007-3-23 12:34: Many usages are explored by people, and it may not be in the help. |
|
| 1 2 Next |
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |