China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-01 13:47
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » (Solved) How to save the file name to a specified location in a batch? View 2,283 Replies 7
Original Poster Posted 2005-09-20 21:11 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Hello everyone!

I would like to ask you all, how can I save the file name to a specified location in a batch file under DOS 7.10? How should such a batch file be written?

For example, I want to save the "34" in 34.txt to "set run=" position in autoexec.bat, that is, set run=34.

[ Last edited by willsort on 2005-9-25 at 00:16 ]
Floor 2 Posted 2005-09-21 18:29 ·  中国 河北 石家庄 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline
You'd better make the running background of the problem more clear, for example, what function you want to implement, how you plan to implement it, etc., or there are better solutions.
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 3 Posted 2005-09-22 19:31 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re quan_zhou:

According to your problem description, I guess you don't need to write 34 into the set run="location" in autoexec.bat. Because a batch program that can solve your problem must first be able to obtain the value of "34", otherwise there is nothing to write. And if it can obtain the value of "34", then why not set run=34 directly in this batch program instead of going to autoexec.bat to set run=? If you mean that the batch program used for setting is called only once, and autoexec.bat needs to be executed every time, then how do you ensure that when the value of 34 changes, autoexec can still be executed correctly?

So, my suggestion is: call a batch program in autoexec.bat, and the function of this batch program is to find 34 and set it to %run%, and how to find 34 depends on what is actually in your 34.txt.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 4 Posted 2005-09-23 11:17 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Thank you very much for Climbing / willsort's attention!
I checked the posts in your forum and this problem has been solved. Actually, as Brother will sort said, calling another batch file can solve it.
The function that autoexec.bat wants to achieve is: directly compare 1.txt with %A% obtained from check.bat.
echo set file=%a% >b.bat //Generate B.bat
Add the following content in autoexec.bat:
call b.bat
compfile c:\1.txt %file%
If they are the same, run the specified program
If not the same, Call check.bat
------------------------------
The function of check.bat (already existing) is: under DOS, compare c:\1.txt with files from D:\sample1.txt to samplen.txt, and set the file name that has the same content as c:\1.txt as variable %A%.
---------------------
Remarks:
c:\1.txt is randomly generated and may be different each time.

In addition, I would like to ask the two brothers a few questions:
1. Can the content of a text be set as a variable under DOS 7.10?
The content of s.tx is 1375905
For example, set 1="content of s.txt"
2. What method can be used under DOS 7.10 to change the content of 3.txt to be like 4.txt
----- 3.txt------
13926584
13595464
13456931
13711364
------------------
-----4.txt-----
1:
13926584
2:
13595464
3:
13456931
4:
13711364
-------------------

Thank you again for everyone's attention, thank you!!!
Floor 5 Posted 2005-09-23 19:00 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re quan_zhou:

If you call b.bat just to set file=%a%, you can directly write it in autoexec.bat, unless your %a% is not referencing an environment variable but is used as a variable indication. Further confusion is why not directly set the value to %file% in check.bat or directly use %a% for comparison in autoexec (compfile c:\1.txt %a%)? This can omit many intermediate twists.

As for fetching the content of a text file into a variable, this is a topic that has been discussed many times before. It depends on the complexity of your s.txt and your requirements for the position of the target to be obtained. If s.txt contains only one word and that's exactly what you want to get, you can use the date or time command to get it; if your s.txt is complex and changeable, you can use third-party tools such as LMOD or gawk, etc., and strings can also be considered. Their advantage is that they are easy to use and can handle various complex needs; if you cannot or are unwilling to use third-party tools, you can refer to the batch processing programs about text traversal (file traversal) that I posted before.

As for the second replacement problem you mentioned, in fact, it is a similar problem to the first one, and you can also try using LMOD/GAWK or the batch processing I mentioned. For their usage and related explanation descriptions, there are many in the past posts, and you can search and see.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 6 Posted 2005-09-23 22:16 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Brother willsort:
Actually, what I'm doing here is so that the next time I start up, I directly compare the%A% from C:\1.txt and the last check.bat. If they are the same, run the specified program. If not, call check.bat to find the file name that's the same as c:\1.txt and store it in %file% so that I can directly compare it after the next start up.
For the above two problems, I wonder if it's possible to trouble Brother willsort to write a brief example using LMOD. Because my English is extremely poor, I can only use LMOD to extract part of the content of a file to another file, and I don't know how to implement other functions.
Thank you very much!
Floor 7 Posted 2005-09-24 12:44 ·  中国 山西 大同 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re: Quanzhou:

Actually, my English can also be said to be very poor. I read a lot of things reluctantly. The main function of LMOD is to filter and convert the source text into the target text according to the specified requirements. If you can generate another file, you are already very close to the requirement of saving it to an environment variable. You only need to add a line "set 1=" in front of it and generate it to be called in a batch file to achieve it.

Off-topic: I feel that using variables or file names without meaning or too general, such as "file a 1 s.txt" in autoexec.bat, is too casual. Please don't take offense .

Regarding the LMOD solution for question 1:

lmod set 1= < s.txt > _setvar.bat
if exist _setvar.bat for %%c in (call del) do %%c _setvar.bat


Regarding the LMOD solution for question 2 (since I don't know if the output digit of the line number can be controlled, so a two-time filtering method is adopted. Maybe Brother Climbing or other friends familiar with LMOD have better methods):

lmod /l* : < 3.txt | lmod /l* > 4.txt

Or like this (they are equivalent. The former is more in line with the writing habit, and the latter is closer to the reading habit):

< 3.txt lmod /l* : | lmod /l* > 4.txt


[ Last edited by willsort on 2005-9-24 at 12:48 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 8 Posted 2005-09-24 17:01 ·  中国 广东 东莞 电信
初级用户
Credits 190
Posts 40
Joined 2005-03-17 00:00
21-year member
UID 37149
Gender Male
Status Offline
Brother willsort:
Thank you very much! Your reply not only helped me solve the problem I encountered but also allowed me to learn things that I can't learn from books.
As for the "off-topic remarks", it's a very bad habit of mine, being casual in doing things. Thanks for the reminder. I will definitely correct it.
Forum Jump: