中国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-25 23:17
47,812 topics / 349,910 posts / today 0 new / 48,264 members
DOS批处理 & 脚本技术(批处理室) » [Original] [XP] File Backup Utility V2.4 (Final) [Updated on 07-4-8]
Printable Version  35,963 / 112
Floor1 namejm Posted 2006-05-22 23:35
荣誉版主 Posts 1,737 Credits 5,226 From 成都

Attachments
文件备份器(Final).rar (117.32 KiB)
Floor2 willsort Posted 2006-05-23 01:47
元老会员 Posts 1,512 Credits 4,432
Re: namejm:

It's a very good batch script, and it can be seen that you have put a lot of effort into it. Therefore, I have a suggestion: transform this thread into an original thread about "Automated File Backup Batch Scripts". The first post should repost the latest source code, and subsequent replies can discuss several details and issues involved. This requires transferring and merging some of your past thread posts, so I need to obtain your consent.

Regarding the execution problem of the at3 command, since I haven't finished reading the code yet, I can't give any opinions. I only speculate that it might be related to the corresponding backup script, so the code of this batch processing needs to be posted.

In addition, just a brief discussion on the following section quoted from the source code:


set /p source= Please enter the path of the file to be backed up:
:: Here, you can prompt to directly drag the backup target into the running window to obtain the source path

for /f "delims=:\" %%i in ("%source%") do set subarea1=%%i
:: It seems to be to obtain the drive letter of the source. Why not use set subarea1=%source:~0,1%

if not "%source%"=="" set source=%source%
:: The meaning of this sentence is unclear, please enlighten me
:: If you want to format the path, you need to use for %%p in ("%source%") do set source=%%~fp

if "%source%"=="" goto input_source
:: It is suggested to assign the selection of directly pressing Enter (that is, %source% is empty) to the operation with high frequency
if "%source%"=="0" exit
if "%source%"=="1" goto backup_task

echo "%source%"|find "%subarea1%:\" > nul
if "%ERRORLEVEL%"=="1" goto input_source
:: Judge whether there is a drive letter in the path? Can it be done with if "%source:~1,2%"==":\"

if "%source%"=="%subarea1%:\" goto forbid
:: Judge whether the path is the root path? When source is C:\\ or C:\., it will not work

if not exist "%source%" goto source_noexist
goto input_object
:: The meaning of object is object, which is ambiguous with the backup target. It is better to change it to target or destination


[ Last edited by willsort on 2006-5-23 at 01:48 ]
Floor3 bagpipe Posted 2006-05-23 12:30
银牌会员 Posts 425 Credits 1,144 From 北京
LZ really has patience. It's so long, longer than my graduation thesis. Admiration, admiration.......... Just as WILLSOFT said, I haven't finished reading the code yet and need to digest it slowly.
Floor4 Climbing Posted 2006-05-23 13:05
铂金会员 Posts 2,753 Credits 6,962 From 河北保定
I think the error with at has little to do with the batch script. It might be due to other aspects.

From the owner's batch script, as long as one at plan runs normally, the others should also be fine.

I respect the owner's patience. But if you just want to implement the file backup function by writing this batch script, it's really simpler to introduce some third - party tools, such as SecondCopy or the synchronization software CmdSync, etc. Of course, personal environments are different, so methods vary. Mine is just a suggestion.
Floor5 doscc Posted 2006-05-23 14:11
中级用户 Posts 93 Credits 256 From 广东
Agree with the suggestion of building 4!

Show respect for the building owner's patience

Although scripts can help us complete some repetitive tasks!
But sometimes it's not bad to use some third-party software.
Floor6 namejm Posted 2006-05-23 14:18
荣誉版主 Posts 1,737 Credits 5,226 From 成都
to willsort Moderator:
I don't know what conditions are required when you perform the operation of "transferring and merging some of your past theme posts". I'm very happy that this script can be further improved by everyone. Please edit it according to your ideas. If there's anything that needs me to do, I will cooperate as much as possible. Thank you, willsort.
Report the problem:
Just now, I suddenly recalled that the scheduled task batch file generated by manual execution shows "…… Whether to rewrite? (YES or NO or All)" (something like that). Now, due to the rush of time, I didn't have time to look closely. It seems that because at runs in the background, it won't make any prompts for commands that need manual confirmation, so it causes the cmd.exe and xcopy.exe processes to always exist, and the backup operation doesn't execute.
Now, adding the /y parameter after the xcopy sentence solves the problem.
I have read everyone's replies. It seems that there are still many details that need to be improved in this script. Because I have to go to work soon, I don't have time to reply one by one. I can only reply after getting off work. Please forgive me. At the same time, please continue to find faults in it, especially see if there are some places that don't have better solutions. Thank you all here.
Floor7 namejm Posted 2006-05-23 18:40
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Thanks to the review of moderator willsort, here are some of my thoughts:

"set /p source= Please enter the path of the file to be backed up:
:: Here you can prompt to directly drag the backup target into the running window to obtain the source path"
——It turns out that you can directly drag it over to display the path. Hehe, unexpected gain. Thanks to willsort here. If the path has spaces, when dragging it over directly, it will automatically add quotes at the beginning and end of the path. And originally, in order to take care of the path with spaces entered manually, the following variable references all added quotes. If the prompt is to use the drag-and-drop method, it will cause the program to error. If manual input is not allowed and only drag-and-drop is allowed, then removing the quotes in the variable references should solve this contradiction. It's hard to choose for the time being.

"for /f "delims=:\" %%i in ("%source%") do set subarea1=%%i
:: It seems to get the drive letter of the source. Why not use set subarea1=%source:~0,1%"
——If the path entered by the drag-and-drop method has spaces, it can only get the first quote. If the solution of the previous step is adopted and only drag-and-drop is allowed, it will cause an error. It seems that the drag-and-drop method is quite error-prone.

"if not "%source%"=="" set source=%source%
:: The meaning of this sentence is unclear. Please give advice
:: If you need to format the path, you need to use for %%p in ("%source%") do set source=%%~fp"
——To be honest, I don't quite understand this. I copied it from the batch program of the Shenshan Hongye CD. At that time, I thought it was a format for getting keyboard input and didn't think too much about it.

"if "%source%"=="" goto input_source
:: It is suggested to assign the choice of directly pressing Enter (that is, %source% is empty) to the operation with high frequency of use
if "%source%"=="0" exit
if "%source%"=="1" goto backup_task"
——My original intention was to detect whether there is input content. If there is none, then force input and not allow skipping. I feel that this processing is better, and I don't plan to change this code for the time being.

"echo "%source%"|find "%subarea1%:\" > nul
if "%ERRORLEVEL%"=="1" goto input_source
:: Judge whether the path contains a drive letter? Can it be used if "%source:~1,2%"==":\" "
——For the same reason as above, when dragging and inputting, only the first quote can be obtained.


"if "%source%"=="%subarea1%:\" goto forbid
:: Judge whether the path is the root path? When source is C:\\ or C:\. it will not work"
——I didn't consider this situation at that time. Thanks to the moderator for the reminder. Now add two more lines of code at the back, which should avoid this error:
if "%source%"=="%subarea1%:\\" goto forbid
if "%source%"=="%subarea1%:\." goto forbid

"if not exist "%source%" goto source_noexist
goto input_object
:: The meaning of object is object, which is ambiguous with the backup target. It is better to change it to target or destination"
——It's embarrassing to say. I have always been worried about English, so I often make jokes. I have changed it in the new code. Thanks for the correction.

The following is the modified code:

[ Last edited by willsort on 2006-5-24 at 01:42 ]
Floor8 namejm Posted 2006-05-23 18:54
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by Climbing at 2006-5-23 13:05:
I respect your patience, but if you're only writing this batch script for file backup, it's actually simpler to use some third-party tools. For example: SecondCopy, or the synchronization software CmdSync, etc. Of course, personal environments are different, so methods vary. Mine is just a suggestion.

Thanks to the boss for providing the clues about these two programs. I searched online, and their functions are very appealing.
But there are two drawbacks: 1. As I said in the update history of this script program, "There are many restrictions on backup software on the Internet." SecondCopy has a 30-day free trial restriction. For rookies like me who don't know how to crack, after using it for 30 days, I may have to adjust the system time forward by N days (not necessarily effective), or back up manually again. And the registration codes on the Internet are all expired, and there seem to be no cracks; 2. Both are in English. This has always been a headache for me. Although I know that not knowing much English is not easy to get along on the Internet and not easy in real life, due to the limitation of my major, I haven't spent much time on English since graduating from college. So the software I use is either developed by Chinese people or has been localized. Pitiful :(
For the above reasons, I decided to make a script program by myself. On one hand, I can practice skills, and on the other hand, I can use it for my friends who are more rookie than me. Bitter smileing……
Floor9 willsort Posted 2006-05-24 02:47
元老会员 Posts 1,512 Credits 4,432
Re namejm:

I have made some changes to the first post of the topic, including modifying the title and adjusting the order of the main content.

Originally, I tried to merge all discussion topics related to this program that brothers posted into here, but I found that brother has put a lot of effort into this script and actually found more than a dozen related topics. In this case, not only is the merging workload heavy, but it will also cause many discussion topics with relatively little relevance to be mixed in the same topic, which反而 reduces the role of the topic. Therefore, I finally decided to only provide links to all related discussion topics in the first post for reference and indexing.

Secondly, the code in brother's 7th floor is moved to the first post. This is due to the following reasons: First, because the code volume is too large, if there are multiple versions with little difference, it will reduce the page opening speed, increase the user's reading time, and consume more forum space and time resources; second, because our principle of publishing the program is to let users obtain the latest version in the most convenient way as much as possible. If the new version is updated in the reply post, it may require scrolling or even turning pages to get it, which raises the threshold for promotion. Therefore, it is suggested that when brother releases the new version of the program, he can also edit the code into the first post.

Again, regarding that small section I quoted, your dilemma can be solved. Users can drag and back up the source, or directly enter the source path (absolute path or relative path). No matter whether it contains quotes or non-standard path reference methods (C:\\, C:\.\), we can solve these incompatible problems through pre-formatting and standardizing the path string. The following statement can remove the quotes in the path, convert the relative path to the absolute path, convert the non-standard path to the standard path (C:\\-->C:\), and judge whether the path effectively exists and whether it is the root path. However, it still cannot resist the illegal characters (>|) in the path. I wonder if other brothers have any better solutions?

Finally, I don't know what environment brother uses to write the code? Judging from the comment width reaching 114, brother may be using a wide-screen monitor, so there is no need to worry about the line break browsing problem of comments. However, according to the code posted in the forum and my system environment (17"+XP+EditPlus2), no matter whether the automatic line break function is enabled or not, the excessive width of comments affects the readability of the code.



[ Last edited by willsort on 2006-5-24 at 02:54 ]
Floor10 namejm Posted 2006-05-24 12:48
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by willsort at 2006-5-24 02:47:
Re namejm:

Finally, I don't know what environment you use to write code? But from the fact that the width of the comment reaches 114, it seems that you may be using a wide-screen monitor, so there is no need to worry about the line break browsing problem of the comment. However, according to the code posted in the forum and my system environment (17"+XP+EditPlus2), whether the automatic line break function is enabled or not, the excessive width of the comment affects the readability of the code.


The boss really saw the problem at a glance. I am using a wide-screen computer, 14''+XP, with a resolution of 1280×768. I used to be in pain because of the inconsistency between the wide screen and the standard 4:3 screen when learning to make web pages. Now I actually forgot this detail. It really woke me up. It seems that I need to find a 4:3 monitor to modify.
I didn't post the thread specifically for writing this script. It was because when making a CD, I needed to extract specified e-books from the CD to the computer. As my interest became stronger and stronger, and my enthusiasm for batch processing became uncontrollable, I fiddled with many scripts on my own computer to enhance the system's functions for self-entertainment. I just came back from work and still have a bit of a headache. I'll take a nap first. I'll reply when I come back from work in the evening. Please forgive me.
Floor11 namejm Posted 2006-05-24 17:32
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Can you use for to parse the path, and if there are illegal symbols, jump to the warning interface?
Floor12 namejm Posted 2006-05-24 23:54
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by willsort at 2006-5-24 02:47:
Re namejm:

set _src=
for %%p in ("%source%") do if exist %%p set _src=%%~fp
if "%_src%"=="" for %%p in (%source%) do if exist %%p set _src=%%~fp
if "%_src:~1,2%"==":\" goto forbid
set source=%_src%


After compressing this code into a single line and testing it, I found it works fine and have updated it into the script. The update position is as follows:


I found an issue and it seems I need to adjust the input prompt.


(The content between
Floor13 willsort Posted 2006-05-25 00:12
元老会员 Posts 1,512 Credits 4,432
Re namejm:

The key issue is that we can't be sure whether there are quotes before and after the path string, so we can't rashly decide whether to enclose the path string with quotes, and thus can't restrict the illegal characters in it. I once had a similar discussion in , and there's no good solution at present.

And any statement that probes and analyzes the path string (whether echoif, for), requires the path string itself to appear in the command line, and if the unconstrained illegal characters obviously disrupt the normal order of the command line. It may even not produce a syntax error prompt, but unexpectedly generate some garbage files.

In your current code, if some users enclose the path with spaces with quotes for safety, the code will obviously have a syntax error and stop. Up to now, we've only tested the legal behaviors of well-meaning users, and haven't really carried out some non-well-meaning extreme boundary tests.

So, it's very difficult to compile a code with strong "robustness", especially in free and flexible batch processing.

The oddity of batch programming: selection of anti-space characters in if statement
http://www.cn-dos.net/forum/viewthread.php?tid=12388#pid100419
Floor14 namejm Posted 2006-05-25 18:32
荣誉版主 Posts 1,737 Credits 5,226 From 成都
Originally posted by willsort at 2006-5-24 02:47:
Re namejm:
The following statements can remove possible quotation marks in the path, convert the relative path to the absolute path, convert the non-standard path to the standard path (C:\\-->C:\), and judge whether the path effectively exists and whether it is the root path.



The above code I inserted into
set source=
set /p source= Please enter the path of the file to be backed up:

and
if not "%source%"=="" set source=%source%
if "%source%"=="" goto input_source
if "%source%"=="0" exit
if "%source%"=="1" goto backup_task

in between cannot remove the quotation marks before and after the path with spaces, but jumps to the interface for prohibiting full disk copying. Is it that I inserted the wrong position?

[ Last edited by namejm on 2006-5-25 at 22:38 ]
Floor15 willsort Posted 2006-05-25 22:30
元老会员 Posts 1,512 Credits 4,432
Re namejm:

I'm very sorry! The problem lies in the line "if "%_src:~1,2%"==":\" goto forbid". This line of code was inserted temporarily by me after completing the path test and before reposting. It caused an error because it wasn't tested! Changing it to "if "%_src:~1,3%"==":\" goto forbid" can solve the problem.

But the above code still can't perfectly solve the problem of path strings of non - existing files and folders. Replacing code with code can solve this problem. Of course, the new code still can't defend against illegal characters like "<|>".

Old code


New code
1 2 3 48  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023