![]() |
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-09-23 14:38 |
47,812 topics / 349,917 posts / today 0 new / 48,273 members |
| DOS批处理 & 脚本技术(批处理室) » (Solved) How to save the file name to a specified location in a batch? |
| Printable Version 2,436 / 7 |
| Floor1 quan_zhou | Posted 2005-09-20 21:11 |
| 初级用户 Posts 40 Credits 190 | |
|
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 ] |
|
| Floor2 Climbing | Posted 2005-09-21 18:29 |
| 铂金会员 Posts 2,753 Credits 6,962 From 河北保定 | |
|
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.
|
|
| Floor3 willsort | Posted 2005-09-22 19:31 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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. |
|
| Floor4 quan_zhou | Posted 2005-09-23 11:17 |
| 初级用户 Posts 40 Credits 190 | |
|
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!!! |
|
| Floor5 willsort | Posted 2005-09-23 19:00 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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. |
|
| Floor6 quan_zhou | Posted 2005-09-23 22:16 |
| 初级用户 Posts 40 Credits 190 | |
|
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! |
|
| Floor7 willsort | Posted 2005-09-24 12:44 |
| 元老会员 Posts 1,512 Credits 4,432 | |
|
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: 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): 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): [ Last edited by willsort on 2005-9-24 at 12:48 ] |
|
| Floor8 quan_zhou | Posted 2005-09-24 17:01 |
| 初级用户 Posts 40 Credits 190 | |
|
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. |
|
|
[ Contact the Union admin team -
中国DOS联盟 -
Standard version ] Sponsored by ifanr Inc | © 2001–2023 |