|
chjlcn
初级用户
 
积分 43
发帖 7
注册 2005-8-5 来自 广东
状态 离线
|
『楼 主』:
ghost连续备份三个分区批处理制作的问题
使用 LLM 解释/回答一下
cls
set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2%
md %todayFolder%
cd %todayFolder%
md c
md d
md e
cd ..
ghost -clone,mode=pdump,src=1:1,dst=g:\ghost\%todayFolder%\d\c.gho -fx -z2 -sure
ghost -clone,mode=pdump,src=1:2,dst=g:\ghost\%todayFolder%\d\d.gho -fx -z2 -sure
ghost -clone,mode=pdump,src=1:3,dst=g:\ghost\%todayFolder%\e\e.gho -rb -z2 -sure
在windows下将ghost改为ghost32可以执行,
但在Dos下执行时创建的目录c,d,e是在g:\ghost\ 而不是在g:\ghost\%todayFolder\ 。
最后c.gho,d.gho.e.gho是在g:\ghost\ 下,而不是我想要的g:\ghos\%todayFolder\c\,
g:\ghost\%todayFolder%\d\,g:\ghost\%todayFolder%\e\
我发现在ghost时路径提示是g:\ghost\\d\c.gho.
%todayFolder%参数无效?怎样才行?
cls
set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2%
md %todayFolder%
cd %todayFolder%
md c
md d
md e
cd ..
ghost -clone,mode=pdump,src=1:1,dst=g:\ghost\%todayFolder%\d\c.gho -fx -z2 -sure
ghost -clone,mode=pdump,src=1:2,dst=g:\ghost\%todayFolder%\d\d.gho -fx -z2 -sure
ghost -clone,mode=pdump,src=1:3,dst=g:\ghost\%todayFolder%\e\e.gho -rb -z2 -sure
Under Windows, changing ghost to ghost32 can execute,
But when executing under Dos, the created directories c, d, e are in g:\ghost\ instead of g:\ghost\%todayFolder\.
Finally, c.gho, d.gho, e.gho are under g:\ghost\ instead of the g:\ghos\%todayFolder%\c\,
g:\ghost\%todayFolder%\d\, g:\ghost\%todayFolder%\e\ that I wanted.
I found that the path prompt when ghost is g:\ghost\\d\c.gho.
Is the %todayFolder% parameter invalid? How can it be done?
|
|
2005-8-5 08:16 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 2 楼』:
使用 LLM 解释/回答一下
试试这样:
cls
set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2%
md g:\ghost\%todayFolder%\c
md g:\ghost\%todayFolder%\d
md g:\ghost\%todayFolder%\e
ghost -clone,mode=pdump,src=1:1,dst=g:\ghost\%todayFolder%\c\c.gho -fx -z2 -sure
ghost -clone,mode=pdump,src=1:2,dst=g:\ghost\%todayFolder%\d\d.gho -fx -z2 -sure
ghost -clone,mode=pdump,src=1:3,dst=g:\ghost\%todayFolder%\e\e.gho -rb -z2 -sure
Try like this:
cls
set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2%
md g:\ghost\%todayFolder%\c
md g:\ghost\%todayFolder%\d
md g:\ghost\%todayFolder%\e
ghost -clone,mode=pdump,src=1:1,dst=g:\ghost\%todayFolder%\c\c.gho -fx -z2 -sure
ghost -clone,mode=pdump,src=1:2,dst=g:\ghost\%todayFolder%\d\d.gho -fx -z2 -sure
ghost -clone,mode=pdump,src=1:3,dst=g:\ghost\%todayFolder%\e\e.gho -rb -z2 -sure
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-8-5 09:05 |
|
|
chjlcn
初级用户
 
积分 43
发帖 7
注册 2005-8-5 来自 广东
状态 离线
|
『第 3 楼』:
使用 LLM 解释/回答一下
多谢关注。
不过在dos下%todayFolder%参数还是空字符串。
创建的目录在g:\ghost\\c.
不行啊…………好烦。
Thanks for your attention.
But the %todayFolder% parameter is still an empty string under DOS.
The created directory is in g:\ghost\\c.
It doesn't work... So annoying.
|
|
2005-8-5 15:47 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 4 楼』:
使用 LLM 解释/回答一下
在纯DOS环境下,根本就不支持这样的设置变量的方式:
set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2%
这种设置方法只能在NT的cmd环境下使用。
In a pure DOS environment, such a way of setting variables is not supported at all:
set todayFolder=%date:~0,4%%date:~5,2%%date:~8,2%
This setting method can only be used in the NT cmd environment.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-8-5 16:00 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 5 楼』:
使用 LLM 解释/回答一下
Re chjlcn:
纯DOS环境下,另有获取日期变量的方法,见于 {8905}批处理编程的异类 第7楼的代码。
另外,如果要用作不支持长文件名系统中(本站的MSDOS7.10是支持的)的文件或者目录名,需要注意观察日期变量中“年”的位数;如果它是4位数,将会被截取后日期变量的最后两个字符,它有可能是2005的05,也有可能是08-06的06,这取决于系统的日期格式。
Re chjlcn:
In a pure DOS environment, there is another method to obtain date variables, which can be found in the code on the 7th floor of {8905} An Oddity in Batch Programming.
In addition, if it is to be used as a file or directory name in a system that does not support long filenames (the MSDOS7.10 on this site supports it), you need to pay attention to the number of digits of "year" in the date variable; if it is a 4-digit year, the last two characters of the date variable will be truncated. It may be "05" of 2005, or "06" of 08-06, depending on the system's date format.
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-8-6 17:50 |
|
|
chjlcn
初级用户
 
积分 43
发帖 7
注册 2005-8-5 来自 广东
状态 离线
|
『第 6 楼』:
使用 LLM 解释/回答一下
:: GetVar.bat - Get from 'PROMPT' text to environment variable
:: Will Sort - 10:29 2005-7-16 - CMD@XP/COMMAND@Win98/MSDOS6.22
@echo off
echo exit | %comspec% /k prompt set %1=%2$_:: > _GetVar.bat
call _GetVar.bat
for %%f in (_GetVar*.*) do del %%f
程序的思路是一个参数设置命令写入文件,调用,删除临时文件。
我查帮助还是不懂
%COMSPEC% 系统 返回命令行解释器可执行程序的准确路径。
$_回车
这一句整句详细解释一下好吗?
echo exit | %comspec% /k prompt set %1=%2$_:: > _GetVar.bat
### 首先分析 `echo exit | %comspec% /k prompt set %1=%2$_:: > _GetVar.bat` 这一整句的含义:
- `echo exit`:`echo` 命令用于输出文本,这里输出 `exit` 这个字符串。
- `|`:管道符号,将前面 `echo exit` 的输出作为后面命令的输入。
- `%comspec%`:获取系统的命令行解释器路径,通常是 `cmd.exe`(在 Windows 系统中)。
- `/k`:`%comspec%` 的参数,表示执行完命令后不关闭命令提示符窗口。
- `prompt set %1=%2`:`prompt` 命令在这里被用来设置一个临时的命令,这里的 `%1` 和 `%2` 是脚本的参数,假设脚本调用时传入了两个参数,`%1` 会被替换为第一个参数,`%2` 会被替换为第二个参数,比如如果传入的是 `varName` 和 `varValue`,那么这里就会变成 `prompt set varName=varValue`。
- `$_`:这里 `$_` 应该是用来表示一个换行符,在批处理中可以用 `$_` 来插入一个换行。
- `::`:在批处理中,`::` 后面的内容被视为注释,这里主要是为了让后面的 `>` 重定向到文件时的语法正确。
- `> _GetVar.bat`:将前面通过管道传递过来的内容重定向到名为 `_GetVar.bat` 的文件中。
整体来说,这一句的作用是:通过 `echo` 输出 `exit`,然后利用管道将其作为输入传递给 `%comspec% /k prompt set %1=%2$_::` 命令,最后将这个组合的结果重定向到 `_GetVar.bat` 文件中,从而在这个临时批处理文件中设置了一个基于传入参数的 `prompt` 相关命令。
|
|
2005-8-7 09:39 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 7 楼』:
使用 LLM 解释/回答一下
嘿嘿,关键就是这一句!自己慢慢理解吧。这是批处理使用技巧中的精华。
Hehe, the key is this sentence! Understand it slowly by yourself. This is the essence in the skills of batch processing.
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-8-7 10:48 |
|
|
chjlcn
初级用户
 
积分 43
发帖 7
注册 2005-8-5 来自 广东
状态 离线
|
『第 8 楼』:
使用 LLM 解释/回答一下
@climbing
可以给点提示要学习哪几个命令吗?
有没有相关的电子书下载?
@climbing
Can you give some hints on which commands to learn?
Are there any relevant e-books for download?
|
|
2005-8-7 18:21 |
|
|
willsort
元老会员
         Batchinger
积分 4432
发帖 1512
注册 2002-10-18
状态 离线
|
『第 9 楼』:
使用 LLM 解释/回答一下
Re chjlcn:
真要详细说起来,可能会很复杂,因为我的表达能力有限,往往不能掌握读者已经知道了什么,还不知能什么。也许将来的DOS书中,我会专文解释这个代码的技巧。
目前只能简单地提供一些掌握它的思路:
1、注释掉删除_GetVar.bat的for语句,然后在命令行执行 getvar today=$D 查看_GetVar.bat的内容;
2、去除echo一句的重定向部分 > _GetVar.bat,然后在命令行执行 getvar today=$D 查看屏幕的输出内容;
3、在命令行分别单独执行:
echo exit | %comspec% /k prompt set today=$D$_::
%comspec% /k prompt set today=$D$_::
prompt set today=$D$_::
然后观察其各自的输出内容,相信你会有所体悟的。
Last edited by willsort on 2005-8-8 at 13:26 ]
Re chjlcn:
To be really detailed, it might be quite complicated because of my limited expression ability. I often can't grasp what the readers already know and what they don't. Maybe in future DOS books, I will write a special article to explain the techniques of this code.
Currently, I can only simply provide some ideas to master it:
1. Comment out the for statement that deletes _GetVar.bat, then execute getvar today=$D in the command line to view the content of _GetVar.bat;
2. Remove the redirection part > _GetVar.bat of the echo line, then execute getvar today=$D in the command line to view the output content on the screen;
3. Execute separately in the command line:
echo exit | %comspec% /k prompt set today=$D$_::
%comspec% /k prompt set today=$D$_::
prompt set today=$D$_::
Then observe their respective output contents, and I believe you will have some insights.
Last edited by willsort on 2005-8-8 at 13:26 ]
|

※ Batchinger 致 Bat Fans:请访问 批处理编程的异类 ,欢迎交流与共享批处理编程心得! |
|
2005-8-8 13:24 |
|
|
chjlcn
初级用户
 
积分 43
发帖 7
注册 2005-8-5 来自 广东
状态 离线
|
『第 10 楼』:
使用 LLM 解释/回答一下
发现在dos下不支持%myDate:~0,2% 这样取字符,有什么函数可以取得一个字符中的一些字符?
I found that %myDate:~0,2% is not supported under DOS. Are there any functions to get some characters from a string?
|
|
2005-8-9 18:03 |
|
|
Climbing
铂金会员
       网络独行侠
积分 6962
发帖 2753
注册 2003-4-16 来自 河北保定
状态 离线
|
『第 11 楼』:
使用 LLM 解释/回答一下
willsort已经给出解决办法了,你没有仔细研究吗?
Has willsort already provided a solution? Haven't you studied it carefully?
|

偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
|
|
2005-8-9 21:35 |
|