本来想和楼主一起交流上面提出的问题(很有意思),可是想了半天不知道该如何回答:)
我现在都不知道应该认为是纯DOS探讨还是大家都用的XP系统的CMD Shell……
当我在论坛检索内查找了楼主发的大部分贴子,才确定这个问题是问非纯DOS的问题,哈哈……
errorlevel 返回值的问题~`
%random% 的问题 DOS批处理
sc 命令的用法 DOS批处理
><nul 是什么意思啊??
一个疑问? 顺便拜师~```
谁能给我具体的讲讲 for /f 这个命令吗?
请高手帮我编一个批量修改文件名的批处理...
……
看到楼主提过的问题中有<>和for /f读文件等问题,
那这上面的好玩的问题是不是应该是有趣的解决方法?
好玩的解决方法如下,它是自己“写”自己的方式读出chkdsk然后直接自动运行。
为了好玩,所以它只能正确运行一次,哈哈……
但楼主想要的那些问题特性和重定向和读文件都用上了:)
还有楼主可能感兴趣的如何不写入无多余的回车符在最后……也用上了:)
下面例子只求好玩,不实用:)
@for /f %%. in (1.txt) do @set /p=%%.<nul>>"%~f0"
@,
最后一行的@,是有原因的,是怕你直接存第一行而不给一个换行符,
所以,@,就是遇到了后面跟着DOS指令也能够正常执行,
但这种好玩的方法只能正常执行一次~:D
上面用到的 "%~f0" 是批处理自己的盘符路径文件名的全称,此信息在 for /? 的帮助信息中可以查找到更多的消息:)
使用 Del "%~f0" 还可以让批处理 “自杀” ,即自己删掉自己:)
自己(批处理本身)向自己“体内”写入新信息还可以用做简单的运行次数或运行日志等特殊应用:)
上面批处理用到的 >>"%~f0" 是将输出的信息不覆盖目标文件内容的情况下追加到目标文件内容的后面。
而 "%~f0" 为什么要将 %~f0(就是批处理自身的全部路径等信息)加上双引号?是因为如果你含有空格的地方运行(如桌面),
那么为了不引起系统错误的判断中间的空格……
例如: CD ABC 123是进不去 "ABC 123"这个目录的,要加双引号系统才知道这是一体的,
所以上面批处理自身信息的表示要用双引号括起来:)
set /p=%%.<nul 是为了去掉你那1.txt中全带了回车换行符的“c h k d s k”,
至于为什么它能够“去掉”回车和换行符号,这里面有一个典故,嘻嘻……
需要象看故事一样欣赏下面的精彩文章:
----------------------------------------------------------------------------------------------------
无奈何签名代码略析
http://www.cn-dos.net/forum/viewthread.php?tid=18838&fpage=1&highlight=%E7%AD%BE%E5%90%8D
----------------------------------------------------------------------------------------------------
上面的文章看完了,楼主就可以做更好玩的东东了~:)
(如果没有看过这篇文章的朋友,请放下手中的任何事情,现在就去看《无奈何签名代码略析》)
(最没用的就是收藏,最有用的就是用立刻去看去学去做一遍来代替没有用的点收藏的动作:)
Last edited by redtek on 2006-11-6 at 10:38 PM ]
Originally, I wanted to communicate with the LZ about the questions raised above (very interesting), but after thinking for a long time, I didn't know how to answer : )
Now I don't even know whether to consider it as purely DOS discussion or the CMD Shell of the XP system that everyone uses...
After I searched most of the LZ's posts in the forum search, I determined that this question is about non-pure DOS issues, haha...
Problem about errorlevel return value~`
Problem about %random% in DOS batch processing
Usage of sc command in DOS batch processing
What does ><nul mean??
A question? By the way, apprenticeship~```
Who can specifically explain the for /f command for me?
Please, expert, help me compile a batch processing for batch-renaming filenames...
……
Seeing that there are problems about <> and for /f reading files and other problems mentioned by the LZ,
Then are these interesting problems supposed to be interesting solutions?
The interesting solution is as follows, it is the way of "writing" itself to read chkdsk and then directly run automatically.
For fun, so it can only run correctly once, haha...
But the LZ's wanted those problem characteristics and redirection and reading files are all used up : )
Also, the LZ may be interested in how not to write redundant carriage return characters at the end... is also used up : )
The following example is only for fun, not practical : )
@for /f %%. in (1.txt) do @set /p=%%.<nul>>"%~f0"
@,
The @, in the last line has a reason, it is to prevent you from directly saving the first line and not giving a line feed,
So, @, is that when encountering the following DOS command can also execute normally,
But this interesting method can only execute normally once~ : D
The "%~f0" used above is the full name of the batch processing's own drive letter path filename, this information can find more messages in the help information of for /? : )
Using Del "%~f0" can also let the batch processing "commit suicide", that is, delete itself~
Self (batch processing itself) writing new information to itself can also be used for special applications such as simple running times or running logs...
The >>"%~f0" used in the above batch processing is appending the output information to cover the target file content's situation to append to the target file content's behind.
And why does "%~f0" want to add %~f0 (that is, batch processing oneself's entire path and other information) with double quotes? It is because if you run where there are spaces (such as desktop),
Then in order to cause the system wrong judgment middle spaces...
For example: CD ABC 123 is not getting into "ABC 123" this directory, to add double quotes the system just knows this is integral,
So the above batch processing oneself information's expression要用 double quotes enclose : )
set /p=%%.<nul is to remove that your 1.txt all took carriage return line feed characters of "c h k d s k",
As for why it can "remove" carriage return and line feed symbols, there is a allusion inside, hee hee...
Need to appreciate the following wonderful article like reading a story:
----------------------------------------------------------------------------------------------------
Brief Analysis of Helpless Signature Code
http://www.cn-dos.net/forum/viewthread.php?tid=18838&fpage=1&highlight=%E7%AD%BE%E5%90%8D
----------------------------------------------------------------------------------------------------
After reading the above article, the LZ can make more interesting things~ : )
(If the friend who hasn't read this article, please put down any thing in hand, go to see "Brief Analysis of Helpless Signature Code" now)
(The most useless is collection, the most useful is to use go to see go to study go to do once to replace the action of collecting uselessly)
Last edited by redtek on 2006-11-6 at 10:38 PM ]