中国DOS联盟论坛

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-10 18:48
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » How do I write this backup and upgrade batch file?
Printable Version  3,377 / 14
Floor1 stonelei Posted 2004-08-25 00:00
初级用户 Posts 14 Credits 172
First, thanks to Climbing for introducing me to such a good place. I didn't even know there was a China DOS Union before, so I hope the veterans here won't mind. Knowledge about DOS is getting less and less now, and this place really lets us review the old and learn the new.
Enough small talk, I want to ask a question, one I've never been able to solve.
> --------------------------------------
> 1. Create a directory on drive C called TBLBAK; if it already exists, don't create it. Then create a directory inside TBLBAK named after the date
(or it can be named some other way too)
> 2. Copy c:\faspic\tbl*.* to C:\tblbak\ previously created directory\.
> 3. Overwrite-copy a:\tbl*.* to c:\faspic\.
> 4. Check whether the directories created by this batch file under c:\tblbak exceed 10. If they do, delete the earliest
created one, i.e. keep at most the latest 10 directories.
> 5. Can one batch file carry out all the above operations? Of course, temporarily created batch files can be ignored.
>
> ---------------------------------------------


There are several difficult points:
1. How do I create a directory name based on the date that DOS can recognize? That is, the year can only take the last few digits; if it goes beyond that, DOS won't recognize it?
2. How do I detect whether those directories it created have already exceeded 10? Or some user-defined number?
3. How do I intelligently delete the earliest-created one while always keeping 10?
4. Aside from temporarily created batch files, how feasible is it to have one batch file do all this?
5. I'm not very capable, so I hope all you experts can lend me a hand and help me out.
Floor2 Climbing Posted 2004-08-25 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
First tell us what operating system this batch file is running under. Is it a pure DOS environment, or the DOS prompt under 9x/nt? Before asking a question, write your environment clearly first.
Floor3 stonelei Posted 2004-08-25 00:00
初级用户 Posts 14 Credits 172
Oh, thanks, it's a pure DOS environment. DOS 6.22.
Floor4 Climbing Posted 2004-08-25 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
I no longer have a DOS 6.22 environment, so it's not easy for me to test. I suggest you first write out what you can, then we'll help you solve the parts you can't solve. Basically all of it can be done with a batch file, of course using third-party tools, especially Horst's PBAT batch utility tools.
Floor5 stonelei Posted 2004-08-25 00:00
初级用户 Posts 14 Credits 172
But I simply can't write the parts for creating the corresponding directory according to the date, checking how many directories are under a directory, and deleting the old directories.
Floor6 stonelei Posted 2004-08-25 00:00
初级用户 Posts 14 Credits 172
Does any expert know? Please help write it, especially the difficult points I mentioned. I just can't figure them out. If I understood those difficult points, my problem would have been solved long ago.
Floor7 Climbing Posted 2004-08-26 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
You yourself aren't making any effort at all, which makes me feel very disappointed。The batch file Climbing wrote for StoneLei (including all the tool programs used, 14KB, click to download)Below is the contents of the batch file:
Floor8 stonelei Posted 2004-08-26 00:00
初级用户 Posts 14 Credits 172
Big brother Climbing, your warm-hearted help really moved me to tears. Here I want to say "thank you" to you, and I will follow your advice and work and study harder in the future. Thank you.
Floor9 autoit Posted 2004-08-27 00:00
系统支持 Posts 339 Credits 904 From 厦门
Brother Stone really is admirable in the way he treats people!!! Salute to Climbing!
Floor10 willsort Posted 2004-09-20 00:00
元老会员 Posts 1,512 Credits 4,432
Re Climbing:
Brother Climbing's program is already quite complete, except for two details:
1. When checking whether a directory exists, using if exist c:\directory\nul cannot detect whether a directory with hidden or system attributes exists, which will cause errors later in the directory creation process. The solution is either dir c:\directory /a | find "c:\directory" /i, or attrib c:\directory | find "direcory" /i, and then use if errorlevel to test the errorlevel returned by find.
2. I am not quite sure how nset parses date strings separated by "-", but since it uses the output of the date command, it should take into account that under DOS6 the date format is not necessarily the Eastern year-month-day style, but the American month-day-year style, unless the country setting is configured in config.sys. Therefore, there should be a problem in the module that checks the number of directories; please adjust it as appropriate.

Floor11 Climbing Posted 2004-09-20 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
Re Willsort:
Brother Willsort really does strive for perfection. To tell the truth, I really didn't think about things that carefully.
1. If there really are hidden or system directories, I suggest the user first manually remove those attributes (actually, not removing them does not affect the program's operation either). Under normal circumstances this problem probably won't come up. But thank you for telling me this method can't be used for directories with hidden or system attributes (I really wasn't very clear about that). Also, under DOS 6.22 there probably is no find command, which is another troublesome matter.
2. The batch file I wrote above really was tested by finding a DOS 6.22 system, then installing and debugging it in a virtual machine. In that DOS 6.22 system, the Date command really did display in yyyy-mm-dd format (without setting any country option). But even if it displays as mm-dd-yyyy, it doesn't matter; just change it to nset /S- curdir=$7$5$6.
Thanks again to brother Willsort for not being stingy with your advice. Actually, writing this program was just to get the job done. I've always been rather careless, so as long as I can muddle through, that's fine, hehe.
Floor12 willsort Posted 2004-09-20 00:00
元老会员 Posts 1,512 Credits 4,432
Re stonelei:

1. As for obtaining the date, I already explained it in another post, but considering that DOS6.22 DATE uses a four-digit year value, and your requirement that you don't want to lose the last two digits, I'll add another method: you can capture the creation and modification date of a file under DOS. The rough code is as follows:


2. As for determining the number of directories, you can operate by transforming the file list, mainly using dir and find. The rough code is as follows:


3. As for floppy disk testing, you can actually use a simple debug script to call DOS int21 functionality to implement it, which avoids bringing in third-party programs to solve the problem and is suitable for an environment that has only a standard DOS configuration. But if your conditions allow it and you do not mind third-party programs, then you can ignore this detail.

4. From the above description, you should be able to understand that this batch file can absolutely be implemented with a single file. In fact, any problem that can be implemented by multiple batch files can be implemented by a single batch file, but sometimes, for design-principle considerations, it is necessary to split it into several modules.

Also, the code portions above are only an offline design based on experience, and have not actually been tested in a DOS6 environment. You can adjust them at any time according to your own needs and any problems that arise, and they are not subject to any form of copyright.

Re Climbing:

I just saw your reply, so I'm replying along with editing this post.

find.exe has been packaged and installed together with DOS since DOS5 as an external command specifically for pipes. Similar commands include fc.exe and more.exe. Perhaps your DOS6.22 is not very complete. Also, edlin and debug are relatively commonly used pipe commands. Unfortunately, edlin was removed after DOS6, which greatly weakened batch files' ability to control text strings, but it has always existed in the nt series.

The date format issue used to be a very troublesome problem for me when using DOS6, because with different country settings, the date formats vary greatly, creating a major challenge for the universality of some of my batch programs. The behavior on your machine may be because the virtual machine's virtualization was incomplete, or because dos6 gets different results for the date from different BIOS versions, or because your dos6.22 was not using the original configuration.

[ Last edited by willsort on 2005-10-13 at 10:29 ]
Floor13 Climbing Posted 2004-09-20 00:00
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
Once again I sigh over how endless the sea of learning is.
Floor14 jlb007 Posted 2004-09-23 00:00
初级用户 Posts 6 Credits 120
I don't understand batch files at all. Do those Chinese characters need to be written into it too?
Floor15 superking Posted 2010-03-16 23:38
新手上路 Posts 11 Credits 25
Very good, I learned something, but why is it incompatible with the Tianhui Chinese character support system?
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023