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-08-07 10:18
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » [Sharing] Advanced Application Examples of the "FOR" Command View 13,020 Replies 59
Floor 31 Posted 2007-06-28 16:47 ·  中国 广东 深圳 电信
新手上路
Credits 6
Posts 3
Joined 2007-06-28 16:03
19-year member
UID 92591
Gender Male
Status Offline
Nice
Floor 32 Posted 2007-07-01 13:03 ·  俄罗斯 莫斯科 华为云
中级用户
★★
我是DOS学者
Credits 367
Posts 180
Joined 2006-05-14 10:53
20-year member
UID 55507
Gender Male
From 重庆
Status Offline
These are all old posts already...
Floor 33 Posted 2007-07-10 15:35 ·  中国 江苏 宿迁 电信
初级用户
★★
Batchs上議院參議長
Credits 199
Posts 105
Joined 2007-06-05 12:00
19-year member
UID 90300
Gender Male
From 江苏
Status Offline
willsort's eternal fan
『生如夏花之绚烂
死若秋叶之静美』 dos做到了
Floor 34 Posted 2007-07-11 12:09 ·  中国 河北 秦皇岛 电信
初级用户
Credits 68
Posts 32
Joined 2007-04-01 12:12
19-year member
UID 83621
Gender Male
Status Offline
Very good, but why does it feel like it's incomplete!!
Floor 35 Posted 2007-07-27 04:29 ·  中国 上海 电信
初级用户
Credits 112
Posts 6
Joined 2005-03-29 00:00
21-year member
UID 37568
Gender Male
Status Offline
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
Floor 36 Posted 2007-07-28 04:23 ·  中国 上海 电信
初级用户
Credits 112
Posts 6
Joined 2005-03-29 00:00
21-year member
UID 37568
Gender Male
Status Offline
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
Floor 37 Posted 2007-08-15 16:58 ·  中国 广东 佛山 顺德区 电信
初级用户
★★
Credits 193
Posts 98
Joined 2007-01-17 11:56
19-year member
UID 76803
Gender Male
Status Offline
/... 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
这家伙很聪明 什么都没留下
Floor 38 Posted 2007-08-26 21:56 ·  中国 云南 红河哈尼族彝族自治州 电信
新手上路
Credits 12
Posts 7
Joined 2007-08-25 03:34
18-year member
UID 95789
Gender Male
Status Offline
Bump
Floor 39 Posted 2007-10-03 03:06 ·  中国 广东 广州 海珠区 电信
新手上路
Credits 4
Posts 2
Joined 2006-10-19 02:39
19-year member
UID 66660
Gender Male
From 广东深圳
Status Offline
Bookmarked
Floor 40 Posted 2007-10-08 21:37 ·  中国 福建 泉州 惠安县 电信
新手上路
Credits 12
Posts 8
Joined 2006-12-26 15:15
19-year member
UID 74620
Gender Male
Status Offline
Why do I see two identical posts?
Floor 41 Posted 2007-10-09 08:09 ·  中国 上海 杨浦区 电信
新手上路
Credits 12
Posts 5
Joined 2007-10-06 11:58
18-year member
UID 99016
Gender Male
Status Offline
This is really explained well, collected, I'll read it slowly
Floor 42 Posted 2007-11-23 00:25 ·  中国 广东 广州 天河区 电信
新手上路
Credits 12
Posts 6
Joined 2007-11-22 00:00
18-year member
UID 103378
Gender Male
Status Offline
I'm new here, just saw this, thanks
Floor 43 Posted 2007-11-24 13:00 ·  中国 湖北 黄冈 电信
初级用户
Credits 25
Posts 16
Joined 2006-10-12 00:35
19-year member
UID 65375
Status Offline
After messing with it for ages, I finally figured out how to use for. Thanks, OP, o(∩_∩)o...
Floor 44 Posted 2007-11-29 15:10 ·  中国 北京 大兴区 联通
初级用户
Credits 78
Posts 37
Joined 2007-11-05 12:35
18-year member
UID 101756
Gender Male
Status Offline
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!
Floor 45 Posted 2007-11-30 00:53 ·  中国 内蒙古 巴彦淖尔 中移铁通
新手上路
Credits 2
Posts 1
Joined 2007-11-23 00:28
18-year member
UID 103480
Gender Male
Status Offline
The content posted by the OP is detailed, Xiao'er gives you a bump!!
Forum Jump: