中国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-09-23 12:57
47,812 topics / 349,917 posts / today 0 new / 48,273 members
DOS批处理 & 脚本技术(批处理室) » [Sharing] Advanced Application Examples of the "FOR" Command
Printable Version  13,644 / 59
Floor31 norlan Posted 2007-06-28 16:47
新手上路 Posts 3 Credits 6
Nice
Floor32 BWSkyer Posted 2007-07-01 13:03
中级用户 Posts 180 Credits 367 From 重庆
These are all old posts already...
Floor33 koala Posted 2007-07-10 15:35
初级用户 Posts 105 Credits 199 From 江苏
willsort's eternal fan
Floor34 guxingyibei Posted 2007-07-11 12:09
初级用户 Posts 32 Credits 68
Very good, but why does it feel like it's incomplete!!
Floor35 gotowelcome Posted 2007-07-27 04:29
初级用户 Posts 6 Credits 112
I've read it several times. There are parts I still don't quite understand.... Even copying the code down and running it doesn't work.
No matter what I do with the part below, I can't get the effect I want... OP, please take another look.

This command can be even more powerful. For example, your todel.txt might not be as clean as in the example above, but generated directly by DIR, with some useless information in it, like this:



Volume in drive D is DATA
Volume Serial Number is C47C-9908

Directory of D:\tmp

09/26/2001 12:50 PM 18,426 alg0925.txt
12/02/2001 04:29 AM 795 bsample.txt
04/11/2002 04:18 AM 2,043 invitation.txt
4 File(s) 25,651 bytes
0 Dir(s) 4,060,700,672 bytes free


for can still extract the filenames from it and operate on them:



for /f "skip=5 tokens=5" %a in (todel.txt) do @if exist %a DEL %a


Of course, the command above performs deletion. If you just want to see which files will be operated on, replace DEL with ech



for /f "skip=5 tokens=5" %a in (todel.txt) do @if exist %a echo %a


You will see:


alg0925.txt
bsample.txt
invitation.txt
Floor36 gotowelcome Posted 2007-07-28 04:23
初级用户 Posts 6 Credits 112
These last couple of days I've kept reading this article... and finally understood a tiny bit of it...
Don't know why, but I have to use this statement to make it show the effect the OP described. But it still doesn't achieve the effect of deleting the other extra characters... still researching...

for /f "skip=3 tokens=5" %%a in (todel.txt) do @echo %%a

alg0925.txt
bsample.txt
invitation.txt
Floor37 luowei14 Posted 2007-08-15 16:58
初级用户 Posts 98 Credits 193
/... hehe, reading the OP's post reminded me of another hard problem
for /f %a in (bingdu.txt) do del %a /f /s /q /a

The contents of bingdu.txt are:
1.txt
2.txt
3.txt
4.txt

I use it to kill viruses... / finally succeeded... thanks, OP... you solved a big problem for me, it had bothered me for a long time
Floor38 hmt Posted 2007-08-26 21:56
新手上路 Posts 7 Credits 12
Bump
Floor39 qq76711184 Posted 2007-10-03 03:06
新手上路 Posts 2 Credits 4 From 广东深圳
Bookmarked
Floor40 zhanfu86 Posted 2007-10-08 21:37
新手上路 Posts 8 Credits 12
Why do I see two identical posts?
Floor41 aoxiang070 Posted 2007-10-09 08:09
新手上路 Posts 5 Credits 12
This is really explained well, collected, I'll read it slowly
Floor42 4417811984 Posted 2007-11-23 00:25
新手上路 Posts 6 Credits 12
I'm new here, just saw this, thanks
Floor43 yangxixing Posted 2007-11-24 13:00
初级用户 Posts 16 Credits 25
After messing with it for ages, I finally figured out how to use for. Thanks, OP, o(∩_∩)o...
Floor44 maker0321 Posted 2007-11-29 15:10
初级用户 Posts 37 Credits 78
I just had to reply. It solved the for trouble that had bothered me for 2 months. I can't help sincerely exclaiming: very good! Very powerful!
Floor45 ttjjj Posted 2007-11-30 00:53
新手上路 Posts 1 Credits 2
The content posted by the OP is detailed, Xiao'er gives you a bump!!
Prev  1 2 3 4  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023