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 14:52
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Original] [XP] File Backup Utility V2.4 (Final) [Updated on 07-4-8] DigestI View 34,122 Replies 112
Floor 16 Posted 2006-05-25 23:33 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
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 willsort at 2006-5-25 22:30:
Re namejm:

set _i=
set source=
set /p source= Please enter the path of the file to be backed up:
for %%s in (%source%) do set /a _i+=1
if "%_i%"=="1" for %%p in (%source%) do set source=%%~p
:: The above two sentences are to judge whether there are quotes in %source%, and if so, remove them
if "%source%"=="" goto input_source
if "%source%"=="0" goto :eof
if "%source%"=="1" goto backup_task
if not exist "%source%" goto source_noexist
for %%p in ("%source%") do if "%%~fp"=="%%~dp\" goto forbid
goto input_destination

When the program is executed in a directory with spaces, when the entered path is current drive letter + colon, it cannot prevent full disk copying. But when it is executed in a directory without spaces, or when the entered path is any drive letter + colon + \, there is no problem. I don't know why.

[ Last edited by namejm on 2006-5-26 at 00:12 ]
Floor 17 Posted 2006-05-26 09:02 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re namejm:

The reason for this is that simply using a drive letter + colon in the path means that the current path of the specified disk is being referenced. So using a drive letter + colon directly in the command line will jump to the current path of the specified disk, not necessarily the root path.

All existing disks have a current path, and they are all valid at the same time; when we have not changed it using cd or other methods, it is usually the root path. Using cd "d:\Program files" will change the current path of drive D, regardless of whether the current drive is D or not; and using copy c:*.* d: will copy all files in the current path of drive C to the current path of drive D, regardless of which drive you are currently on.

This should be considered an inherent path reference technique that has existed from DOS to CMD, just like. and.. do. If you want to escape d: to the root path of drive D, it is equivalent to changing the inherent convention of the command line, which will instead cause confusion for some people. In my new code, I intentionally tested the performance when the current path of a non-current drive is not the root path (testing drive E with the current path of drive C being "C:\Documents and Settings"), and the result is satisfactory, it did not jump to forbid.
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 18 Posted 2006-05-26 23:21 ·  中国 山西 运城 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re namejm:

According to the hint from brother bagpipe in , change the two lines of code that remove the quotes into one line. I once also had a speculation about the priority of % being greater than " greater than ^, but I didn't know how to use it flexibly, and was going around in various for/if structures, feeling quite ashamed!

Thanks a lot to brother bagpipe for the teaching!


set source=%source:"=%


How to remove quotes from parameters passed in by the user?
http://www.cn-dos.net/forum/viewthread.php?tid=20838&fpage=1
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 19 Posted 2006-05-27 00:04 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
I have seen the post from brother bagpipe, and I have updated the code related to the XP file backup tool. Thanks to the two experts here.
Floor 20 Posted 2006-05-27 00:18 ·  中国 辽宁 锦州 中移铁通
荣誉版主
★★★
Credits 1,338
Posts 356
Joined 2005-07-15 12:09
20-year member
UID 40733
Gender Male
Status Offline
To willsort

Regarding removing the double quotes at the beginning and end of parameters, I seem to remember discussing it with you.

See: http://www.cn-dos.net/forum/viewthread.php?tid=17785

Item 1 of post 5.
  ☆开始\运行 (WIN+R)☆
%ComSpec% /cset,=何奈无── 。何奈可无是原,事奈无做人奈无&for,/l,%i,in,(22,-1,0)do,@call,set/p= %,:~%i,1%<nul&ping/n 1 127.1>nul

Floor 21 Posted 2006-05-27 09:13 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
I want to extract the path in the "Command Line" column in the at command. First, I export the result of the at command to a text file, and find the format as follows:

Status ID     Date                    Time          Command Line
-------------------------------------------------------------------------------
1 Monthly execution date: 1 2 3 4 5 6 7...12:40 C:\WINDOWS\system32\Jiayi Financial Data Backup.bat
2 Monthly execution date: 1 2 3 4 5 6 7...19:00 C:\WINDOWS\system32\Jiayi Financial Data Backup.bat
3 Monthly execution date: 1 2 3 4 5 6 7...22:00 C:\WINDOWS\system32\Jiayi Financial Data Backup.bat
There are several square black dots in between (Directly copying the above content and saving it as a text file will not have them, but if you use the at>list.txt command, you will find that there are square black dots). I don't know what is used to separate the rows and columns in this format, which makes it impossible to use the for command to extract.
What should I do?
It would be even better if I can extract without generating temporary files.

The above problem has found a solution, but it is not perfect because temporary files are still generated. The code is as follows:
@echo off
del /q "%tmp%\list.txt">nul 2>nul
at>"%tmp%\list.txt"
(for /f "skip=2 tokens=4 delims=\" %%i in (%tmp%\list.txt) do (find /i "Code by JM" %systemroot%\system32\%%i >nul 2>nul && echo %%i created by a specific program))
del /q "%tmp%\list.txt">nul 2>nul
pause>nul


[ Last edited by namejm on 2006-5-27 at 11:04 ]
Floor 22 Posted 2006-05-27 09:36 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
The commands used are:
at 22:00 /every:M,T,W c:\windwos\system32\家易理财数据备份.bat
When checking the list with the at command, the result is as follows:

Status ID Date Time Command line
-------------------------------------------------------------------------------
1 Execution date of every month: 1 2 3 4 5 6 7...12:40 C:\WINDOWS\system32\家易理财数据备份.bat
2 Execution date of every month: 1 2 3 4 5 6 7...19:00 C:\WINDOWS\system32\家易理财数据备份.bat
3 Execution date of every month: 1 2 3 4 5 6 7...22:00 C:\WINDOWS\system32\家易理财数据备份.bat
4 Execution date of every month:... 22:00 c:\windwos\system32\家易理财数据备份.bat
Is it that my computer is not displaying normally?
(Another thing: When using the function to insert an image in the forum, it seems that only images on the network can be inserted. Can't I insert local ones?)
Floor 23 Posted 2006-05-27 10:57 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Assuming the files are in a text format, in a batch script (using Windows batch commands), you could do something like this (but this is a simplified example, adjust according to actual situation):

```batch
@echo off
findstr "C:\WINDOWS\system32\test.bat" 2.txt > extracted.txt
```

This would find the line containing "C:\WINDOWS\system32\test.bat" in 2.txt and put it into extracted.txt. But if you are using a programming language like Python, it could be:

```python
with open('2.txt', 'r') as f:
content = f.read()
target_line =
if target_line:
with open('extracted.txt', 'w') as f_out:
f_out.write(target_line)
```

This Python code reads the content of 2.txt, finds the line that contains the target path, and then writes that line to extracted.txt. Please note that the actual implementation may need to be adjusted according to the specific operating environment and more detailed requirements.
Floor 24 Posted 2006-05-28 14:28 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Found a problem:
When there is no updated backup, that is, when xcopy prompts "0 files copied", according to my intention, I don't need to write any content in the log.txt file, but it actually writes content. Does xcopy count as successful when copying 0 files? If it does, how should && and the subsequent content be written?

[ Last edited by namejm on 2006-5-28 at 17:17 ]
Floor 25 Posted 2006-05-28 22:05 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re namejm:

The record output of the at command on floor 21 uses newline characters (ASCII: 0A) instead of carriage return newline characters (ASCII: 0D 0A) as line endings, and the record fields are separated by ordinary spaces. Because the notepad tool can only recognize carriage return newline characters, the lines are displayed stuck together, but in my test, this does not affect the for to recognize the at command output. The following command executes normally.

for /f "skip=2 delims=\ tokens=4" %%f in ('at') do ...

The 4th record on floor 22. It is because the three execution days (Monday Tuesday Wednesday) cannot be displayed at the same time, so it is replaced with an ellipsis, which does not affect the task attributes. If you want to extract the execution days of the task, you need other methods.

The difference comparison on floor 23 depends on what type of difference the file is, whether file 2.txt is always larger than 1.txt, or 1/2 have different contents from each other, whether the same records are in the same line, etc.? This determines the complexity of the code.

The return value of xcopy on floor 24 is indeed such a rule, because it found the source file and there were no errors or being aborted by the user during the copying process. The temporary solution is to use find/findstr to filter the xcopy output results.

xcopy /d /h /i /k /f /s /y "%source%" "%destination%" | find "->">nul && (...
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 26 Posted 2006-05-29 23:24 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
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 willsort at 2006-5-28 22:05:
Re namejm:

The difference comparison at floor 23 depends on what type of difference the file is. Is file 2.txt always larger than 1.txt, or do 1 and 2 have different contents from each other, and whether the same records are in the same line, etc.? This determines the complexity of the code.

2.txt is always larger than 1.txt
My original intention is: detect the bat batch processing program used in the at task, extract the bat file name in the "Command Line" column, and then compare it with the bat file in the %systemroot%\system32 directory. If it is not in the at task column and is created by this program (identifier is Code by JM), then delete the bat file.
How to handle this?
Floor 27 Posted 2006-06-01 01:46 ·  中国 浙江 杭州 电信
荣誉版主
★★★★
batch fan
Credits 5,226
Posts 1,737
Joined 2006-03-10 00:38
20-year member
UID 51697
From 成都
Status Offline
Want to find the bat batches created by a specific program (with the identifier "Code by JM") among all bat files in the %systemroot%\system32 directory. However, the result shows all bat batches, and I don't know why.

@echo off
:: Why are those not created by the specific program also displayed in the result?
for /f %%i in ('dir /a /b %systemroot%\system32\*.bat') do (find /i "Code by JM" %systemroot%\system32\*.bat>nul 2>nul && echo %%i was created by the specific program)
pause
Floor 28 Posted 2006-06-01 17:08 ·  中国 山西 临汾 中移铁通
元老会员
★★★★
Batchinger
Credits 4,432
Posts 1,512
Joined 2002-10-18 00:00
23-year member
UID 19
Gender Male
Status Offline
Re: namejm:

The code problem on floor 27 is in find (the part in red bold is the modified result).


@echo off
:: Why are non-specific program-created ones also displayed in the result?
for /f %%i in ('dir /a /b %systemroot%\system32\*.bat') do (find /i "Code by JM" %%i >nul 2>nul && echo %%i was created by a specific program)
pause


Analyzing the requirement of floor 26, it can be achieved without comparing files. Based on the above code, make the following modifications; the code has not been tested at all, please use with caution!

for %%i in ("%systemroot%\system32\*.bat") do (
at | find /i " %%i" >nul 2>nul || find "Code by JM" "%%i" >nul 2>nul && echo del /f %%i
)


[ Last edited by willsort on 2006-6-1 at 17:11 ]
※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得!
Floor 29 Posted 2006-06-01 17:20 ·  中国 安徽 铜陵 移动
中级用户
★★
Credits 230
Posts 104
Joined 2006-04-21 12:22
20-year member
UID 54192
Gender Male
Status Offline
The moderator is really a good person! Thank you!
━━━━━━━
漏漏®的e
━━━━━━━
Floor 30 Posted 2006-06-01 19:51 ·  中国 四川 成都 鹏博士宽带
荣誉版主
★★★★
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 willsort at 2006-6-1 17:08:
Re namejm:

The problem with the code on floor 27 is in the find (the red bold part is the modified result).


Quote:
@echo off
:: Why are files not created by the specific program also displayed in the result?
for /f %%i in ('dir /a /b %systemroot%\system32\*.bat') do (find /i "Code by JM" %%i >nul 2>nul && echo %%i was created by the specific program)
pause



Analyzing the requirement of floor 26, it can be achieved without comparing files. Based on the above code, make the following modifications; the code has not been tested at all, please use it with caution!
CODE:
--------------------------------------------------------------------------------

for %%i in ("%systemroot%\system32\*.bat") do (
at | find /i " %%i" >nul 2>nul || find "Code by JM" "%%i" >nul 2>nul && echo del /f %%i
)

Both codes fail to achieve the goal. The first one will display "File not found - ×××" if >nul 2>nul is removed. The second one simply has no display. I don't know why.
Forum Jump: