中国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-09 00:13
47,811 topics / 349,895 posts / today 0 new / 48,253 members
DOS批处理 & 脚本技术(批处理室) » [Help] zw19750516, please come in for a moment, thanks
Printable Version  1,708 / 16
Floor1 quya Posted 2008-06-03 22:28
高级用户 Posts 172 Credits 558 From 江苏
Here's another use of the FOR statement. Please help me figure out how to get the exact result.

My batch file test1.cmd is as follows



The result is:



The result I want:

quya.txt
c:\x.txt (of course C could also be D)
d:\test\y

How should I do it? Thanks!
Floor2 26933062 Posted 2008-06-03 22:38
银牌会员 Posts 879 Credits 2,268
Can I give it a try


[ Last edited by 26933062 on 2008-6-3 at 10:40 PM ]
Floor3 bat-zw Posted 2008-06-03 22:42
金牌会员 Posts 1,276 Credits 3,105

ps: In the future, when asking for help, please don't call me out by name directly. There are plenty of experts here; I'm really nothing special.

[ Last edited by zw19750516 on 2008-6-3 at 10:44 PM ]
Floor4 quya Posted 2008-06-03 22:48
高级用户 Posts 172 Credits 558 From 江苏
The second reply is wrong this time. You can't search for REM, because I'm only using REM temporarily here; I don't want to leave junk files on your hard drives. In the actual operation it will be other code.

The third reply got rid of the junk in the last line, but it still didn't solve the problem of the variable in the second line not expanding.
Floor5 bat-zw Posted 2008-06-03 23:03
金牌会员 Posts 1,276 Credits 3,105
Hehe, I really did forget about that. Wait, let me think some more...
Floor6 bat-zw Posted 2008-06-03 23:07
金牌会员 Posts 1,276 Credits 3,105
Originally posted by quya at 2008-6-3 22:48:
The second reply is wrong this time. You can't search for REM, because I'm only using REM temporarily here; I don't want to leave junk files on your hard drives. In the actual operation it will be other code.

The third reply got rid of the junk in the last line, but it still didn't solve the problem of the variable in the second line not expanding.

This time it should be fine:


[ Last edited by zw19750516 on 2008-6-3 at 11:17 PM ]
Floor7 quya Posted 2008-06-03 23:24
高级用户 Posts 172 Credits 558 From 江苏
Ah, that's really amazing!

If it could be modified a bit more to remove the junk line too—for example, judging that a line has lots of spaces (which is unlikely to be a filename)—that would be even better. Otherwise, using "in" to exclude lines might accidentally exclude other things too.

I never thought of do call, echo. Although I can guess part of it, I'd still like a detailed explanation. Thanks!

Going to sleep now, see you tomorrow.

[ Last edited by quya on 2008-6-3 at 11:26 PM ]
Floor8 pusofalse Posted 2008-06-03 23:28
银牌会员 Posts 646 Credits 1,604
Originally posted by zw19750516 at 2008-6-3 11:07 PM:

This time it should be fine:
Floor9 HAT Posted 2008-06-03 23:48
版主 Posts 5,017 Credits 9,023
Originally posted by quya at 2008-6-3 11:24 PM:
Ah, that's really amazing!

If it could be modified a bit more to remove the junk line too—for example, judging that a line has lots of spaces (which is unlikely to be a filename)—that would be even better. Otherwise, using "in" to exclude lines might acci ...


You can think of for as a special command-line interpreter. When the for command is initialized, it has already expanded all referenced variables, which means %%i gets replaced with rem sssss>>%systemroot%\x.txt

call can be understood as a child process opened by for. Inside this child process, the system environment variable %systemroot% gets replaced once again with the real value.
Floor10 bat-zw Posted 2008-06-04 00:28
金牌会员 Posts 1,276 Credits 3,105
Originally posted by quya at 2008-6-3 23:24:
Ah, that's really amazing!

If it could be modified a bit more to remove the junk line too—for example, judging that a line has lots of spaces (which is unlikely to be a filename)—that would be even better. Otherwise, using "in" to exclude lines might acci ...

I'm going to sleep too. This ought to be able to identify it without mistakenly excluding anything else.
Floor11 26933062 Posted 2008-06-04 01:23
银牌会员 Posts 879 Credits 2,268
:
Floor12 pusofalse Posted 2008-06-04 01:34
银牌会员 Posts 646 Credits 1,604
At the end? Shouldn't it be at the beginning?
Floor13 26933062 Posted 2008-06-04 07:33
银牌会员 Posts 879 Credits 2,268
This way there will absolutely be no mistaken exclusions.
Floor14 cuihanjie Posted 2008-06-04 23:33
初级用户 Posts 13 Credits 26
I'm totally confused from reading this...
Floor15 quya Posted 2008-06-04 23:46
高级用户 Posts 172 Credits 558 From 江苏
First, let me ask everyone a question: what does the "," after CALL mean? Does it have any special meaning?

Second, you all may have misunderstood the original intent of this program. This small piece of code is part of an encrypted batch file, meant to interfere with other people analyzing the encrypted variables by using >>filename. Of course, the line “for /f "tokens=2 delims=>" %%i in ('findstr /v "%%i" %0') do call,echo %%i” itself is also considered part of what gets encrypted.

In the end, "ECHO %%i" will be replaced with "del %%i"

So the most important thing is not really excluding the FOR statement itself, but excluding cases that might generate things like “del *.*”, which could cause unpredictable major errors. Although that's not very likely, it would be best if it can be taken into account, just in case. This time 26933062's programming approach drifted away from what I had in mind, though of course that was because I didn't explain it clearly, so that's my fault.

If instead of deleting the file being analyzed by others, it wrote false information to it, that would of course be best, but programming that way would be too complex and bloated, so it's not very feasible. What I want is to use relatively simple statements to create a good effect.

Although batch file encryption is difficult, if multiple methods are used together, it can still accomplish something.

[ Last edited by quya on 2008-6-4 at 11:48 PM ]
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023