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-06-24 16:32
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] [XP] File Backup Utility V2.4 (Final) [Updated on 07-4-8] DigestI View 34,138 Replies 112
Floor 76 Posted 2006-09-15 20:22 ·  中国 上海 东方有线
中级用户
★★
Credits 255
Posts 57
Joined 2003-06-26 00:00
22-year member
UID 5927
Gender Male
Status Offline
Now the computer in my unit is a Lenovo with Huidun protection. Data cannot be saved on the C drive. Therefore, the installations and configuration files of Mozilla Firefox and Thunderbird cannot be saved. Also, many programs need to put things in "C:\Documents and Settings", and the folder location cannot be moved, which is really troublesome. Recently, this is how I save and back up. Once when the restore card was unlocked, I edited the "Path" variable in the properties of "My Computer", put the path of winrar in it, and then wrote a file to save settings:

mkbksd.bat
@rar a -u -as -ep3 -r e:\hj\backup\bk\bkfxsd.rar "C:\Documents and Settings\Administrator\Application Data\Mozilla"
@rar a -u -as -ep3 -r e:\hj\backup\bk\bkbirdsd.rar "C:\Documents and Settings\Administrator\Application Data\Thunderbird"

Restore settings
restore.bat
e:
@cd "e:\hj\backup\bk"
REM Try to restore with the shutdown backup file
@rar x -ep3 -o+ bkfxsd.rar
@rar x -ep3 -o+ bkbirdsd.rar

I think if the content of Path cannot be modified, the absolute path of rar can also be put in the script. It can be used simply. Of course, it cannot be compared with the great work of the building owner. Just I want to say that I also had the plan to write such a script, and now it is labor-saving and happy.
Floor 77 Posted 2006-09-15 22:08 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
What a lot of effort this must take.
Floor 78 Posted 2006-09-15 22:46 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
This program is not perfect. I just tested it. I added a backup job and then deleted this backup, but the backup file generated by the program was not deleted, and the startup item in the startup items did not delete either. :o
Floor 79 Posted 2006-09-15 23:05 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by htysm at 2006-9-15 22:46:
This program is not perfect. I just tested it. I added a backup job and then deleted this backup, but the backup file generated by the program was not deleted, and the startup item in the startup item was not deleted either. :o

  Did you use the built-in delete function of this program to delete it? If you use the built-in one to delete, it should be able to delete the startup item in the startup item. I have tested it for a long time. If it really cannot be deleted, please describe your operation in detail to see which part is wrong.

  You said that the backup file generated by the program was not deleted. Does it mean the bat file placed under %programfiles% was not deleted, or the file copied after the backup was successful was not deleted? If it is the latter, then it is exactly what the backup task needs: even if the program deletes it, the file is still retained. If it is the former, please describe your operation in detail.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 80 Posted 2006-09-16 01:03 ·  中国 上海 东方有线
中级用户
★★
Credits 255
Posts 57
Joined 2003-06-26 00:00
22-year member
UID 5927
Gender Male
Status Offline
I suggest trying unxutils, talk later.
Floor 81 Posted 2006-09-16 03:08 ·  中国 上海 东方有线
中级用户
★★
Credits 255
Posts 57
Joined 2003-06-26 00:00
22-year member
UID 5927
Gender Male
Status Offline
Actually, the batch commands under DOS are quite rudimentary. Many times, it's difficult to achieve the effect we want. At this time, it's a good idea to use some Unix tools ported to Windows, which is likely to get twice the result with half the effort.

See http://unxutils.sourceforge.net/

For example, you can use dirname to separate the path name from the file name, etc. I found it very useful when writing scripts. The following is a draft of my script to add tar & gzip compression to the right-click menu. My level is very low, so I put it out for everyone to have a laugh.

set tmpdir=e:\temp\
set progdir="D:\Program Files\UnxUtils\usr\local\wbin\"
%progdir%echo -n -E %1 >%tmpdir%1.txt
%progdir%dirname %1 >%tmpdir%2.txt
%progdir%gawk "{print length($0)+2}" %tmpdir%2.txt > %tmpdir%3.txt
for /F %%i in (%tmpdir%3.txt) do %progdir%gawk "{print substr($0,\"%%i\")}" %tmpdir%1.txt > %tmpdir%4.txt
for /F "delims=?" %%j in (%tmpdir%4.txt) do set bsname=%%j
%progdir%gawk "BEGIN{FS=\".\"}$0 ~/\..?.?.?$/{NF=NF-1;print $0}" %tmpdir%4.txt >%tmpdir%5.txt
%progdir%test -s %tmpdir%5.txt
if %ERRORLEVEL%==1 goto noext
for /F "delims=?" %%i in (%tmpdir%5.txt) do %progdir%tar cvf "%%i.tar" "%bsname%" && %progdir%gzip "%%i.tar"
goto end
:noext
for /F "delims=?" %%i in (%tmpdir%4.txt) do %progdir%tar cvf "%%i.tar" "%bsname%" && %progdir%gzip "%%i.tar"
rem del /Q /S %tmpdir%1.txt
rem del /Q /S %tmpdir%2.txt
:end

Modify the registry

Windows Registry Editor Version 5.00


@="Compress with tar"


@="D:\\Program Files\\UnxUtils\\bin\\mktgz.bat \"%L\""


@="Compress with tar"


@="D:\\Program Files\\UnxUtils\\bin\\mktgz.bat \"%L\""
Floor 82 Posted 2006-09-19 06:19 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Originally posted by hj_18 at 2006-9-16 03:08:
For example, you can use dirname to separate the path name from the file name, etc.


  Actually, if you just need to separate the path name from the file name, you don't need third-party software. The for statement in CMD can do it. %%~pi represents the path name, %%~ni represents the file name, %%~nxi represents the file name with extension... Hehe, through continuous improvement by Microsoft, CMD has become very powerful. It's just limited by our understanding, and it's difficult to give full play to all its functions. What seems difficult to complete, as your understanding deepens, you will find that you are getting closer to success. Finally, you can solve problems through CMD, keep making new discoveries, and keep having new surprises. This is the charm of the CMD command line, and this is also the motivation for us to keep exploring the CMD command line tirelessly. Hehe, a little sentiment, a bit off topic.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 83 Posted 2006-09-19 21:03 ·  中国 上海 东方有线
中级用户
★★
Credits 255
Posts 57
Joined 2003-06-26 00:00
22-year member
UID 5927
Gender Male
Status Offline
I just feel that DOS can't directly assign the output result of a command to a variable, and I have to use a temporary file and FOR, which is a bit annoying. Also, things like IF statements can't be followed by compound statement bodies, and several statements have to be written on one line, which is not nice in terms of format. Using FOR to read things from a file is never as convenient as gawk and so on. I might as well try perl or something.
Floor 84 Posted 2006-09-20 00:58 ·  中国 广东 佛山 广东睿江科技有限公司
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
DOS can directly assign the output result of a command to a variable. It's just that a variable can only receive one line of content at a time, and you can completely do without temporary files. If you use temporary files, either your skills are not enough, or the temporary files have other uses, or... or it's some kind of limitation that all command-line tools can't get around.

The if statement can still be followed by a compound statement body. You can enclose the compound statement body with a pair of parentheses in both the set statement and the command statement of if set command. Maybe you use it less.
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 85 Posted 2006-09-20 08:57 ·  中国 广东 云浮 电信
新手上路
Credits 14
Posts 7
Joined 2006-09-20 08:51
19-year member
UID 63157
Status Offline
The first time I saw such a powerful batch script, give it a thumbs up!
Floor 86 Posted 2006-09-20 21:08 ·  中国 上海 东方有线
中级用户
★★
Credits 255
Posts 57
Joined 2003-06-26 00:00
22-year member
UID 5927
Gender Male
Status Offline
Originally posted by namejm at 2006-9-20 12:58 AM:
  DOS can directly assign the output result of a command to a variable. However, a variable can only receive the content of one line at a time. It can completely be done without temporary files; if temporary files are used...


Can you please teach me? Give an example. I really don't understand. Thank you.
Ah, after reading the post at the top, I understood the second question.

Today I understood the first question.
http://www.cn-dos.net/forum/viewthread.php?tid=23405&fpage=1&highlight=

[ Last edited by hj_18 on 2006-9-27 at 20:08 ]
Floor 87 Posted 2006-09-20 23:14 ·  中国 广东 深圳 联通
新手上路
Credits 2
Posts 1
Joined 2006-09-14 00:08
19-year member
UID 62524
Status Offline
The xcopy_parameter parameter was not used. Is there a bit of a bug?
Floor 88 Posted 2006-10-13 23:12 ·  中国 上海 宝山区 电信
初级用户
★★
Credits 153
Posts 68
Joined 2006-10-12 22:25
19-year member
UID 65507
From 上海
Status Offline
Friendly reminder, there is a small error here:

echo ecoh does not exist, maybe it has been renamed, moved or deleted

Here ECOH should be ECHO, hehe

Incomplete, unable to restore the backup file!

[ Last edited by uemuem on 2006-10-13 at 23:14 ]
个人主页-找餐厅:http://www.canting.cc
Floor 89 Posted 2006-10-14 00:27 ·  中国 四川 成都 移动
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
ecoh is indeed a typo for echo, thank you for your reminder, it has been modified.

May I ask under what circumstances you can't restore the backup file?
尺有所短,寸有所长,学好CMD没商量。
考虑问题复杂化,解决问题简洁化。
Floor 90 Posted 2006-10-14 01:57 ·  中国 上海 宝山区 电信
初级用户
★★
Credits 153
Posts 68
Joined 2006-10-12 22:25
19-year member
UID 65507
From 上海
Status Offline
Originally posted by namejm at 2006-10-14 00:27:
  ecoh is indeed a typo of echo, thanks for your reminder, it has been modified.

  In what situation are you unable to restore the backup file?


The previous one was a prompt for an error, so I noticed it

In the case where the source file does not exist but the backup file exists, the backup file cannot be restored to the source file's location, and there is no error prompt...
I don't know exactly where the problem is, and I can't understand the code either, to be honest! :lol:
个人主页-找餐厅:http://www.canting.cc
Forum Jump: