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-06-20 04:44
中国DOS联盟论坛 » DOS疑难解答 & 问题讨论 (解答室) » Please clarify the specific content related to the "FOR statement / the secret" you want to express, as the current description is too vague. For example, is it about the syntax of the FOR statement in a certain programming language and the meaning of the "/" in it, or something else? Please provide more detailed information. View 3,588 Replies 25
Floor 16 Posted 2006-10-26 05:05 ·  中国 河南 南阳 中移铁通
初级用户
Credits 122
Posts 12
Joined 2004-04-24 00:00
22-year member
UID 23125
Gender Male
Status Offline
Command Prompt
In batch processing

Remembered, thank you
Floor 17 Posted 2006-10-26 05:08 ·  中国 河南 南阳 中移铁通
初级用户
Credits 122
Posts 12
Joined 2004-04-24 00:00
22-year member
UID 23125
Gender Male
Status Offline
For the `for` command in DOS, there are several common usages:

1. `for %variable in (set) do command [command-parameters]` - Iterates over a set of files or values. For example, `for %i in (*.txt) do type %i` to display the contents of all text files.

2. `for /f ["options"] %variable in (file-set) do command [command-parameters]` - Reads the contents of a file and performs commands on each line. For example, `for /f "delims=" %i in (test.txt) do echo %i` to echo each line in the test.txt file.

3. `for /l %variable in (start, step, end) do command [command-parameters]` - Performs a loop from the start number to the end number with a specified step. For example, `for /l %i in (1,1,5) do echo %i` to echo numbers 1 to 5.

4. `for /r [[drive:]path] %variable in (file-set) do command [command-parameters]` - Recursively searches for files in a directory tree. For example, `for /r c:\ %i in (*.exe) do echo %i` to echo all executable files in the C drive and its subdirectories.
Floor 18 Posted 2006-10-26 05:13 ·  中国 河南 南阳 中移铁通
初级用户
Credits 122
Posts 12
Joined 2004-04-24 00:00
22-year member
UID 23125
Gender Male
Status Offline
The format is

for/? %? + method + (range) + action + starting object + %?

Is it like this?
Floor 19 Posted 2006-10-26 05:19 ·  中国 河南 南阳 中移铁通
初级用户
Credits 122
Posts 12
Joined 2004-04-24 00:00
22-year member
UID 23125
Gender Male
Status Offline
It means what kind of way and within what range to perform an action on an object by taking the desired result as a variable %X, and then display the result?
Floor 20 Posted 2006-10-26 12:15 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  Well, it's roughly like this. As long as you truly understand its principle by yourself. It is still recommended to practice the use of the for statement more. After practicing more, you will naturally have a better understanding of it and be more proficient in using it to solve problems.
Floor 21 Posted 2006-10-27 08:04 ·  中国 河南 南阳 中移铁通
初级用户
Credits 122
Posts 12
Joined 2004-04-24 00:00
22-year member
UID 23125
Gender Male
Status Offline
Okay, thank you. I'll take a look at the help in cmd.
Floor 22 Posted 2006-10-27 08:14 ·  中国 河南 南阳 中移铁通
初级用户
Credits 122
Posts 12
Joined 2004-04-24 00:00
22-year member
UID 23125
Gender Male
Status Offline
FOR /F ["options"] %variable IN (file-set) DO command [command-parameters]
FOR /F ["options"] %variable IN ("string") DO command [command-parameters]
FOR /F ["options"] %variable IN ('command') DO command [command-parameters]

file-set refers to specifying a file or files.
"string" refers to specifying a string directly.
'command' refers to executing a command and using its output.

Can "options" load these
eol=c
skip=n
delims=xxx
tokens=x,y,m-n
usebackq
Floor 23 Posted 2006-10-27 21:46 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

Re: ghtfuo

  file-set: represents that the object for which for is executed is a file, or multiple files, and supports wildcards "?" and "*" at the same time;

  "string": indicates that the object for which for is executed is a string, such as the string "www.Cn-Dos.Net";
  The result of executing for /f "tokens=1,* delims=-" %i in ("www.Cn-Dos.Net") do @echo %i+%j is: "www.Cn+Dos.Net";

  'command': indicates that the object for which for is executed is the output of a command, such as the command "ipconfig /all";
  The result of executing for /f "delims=: tokens=1*" %i in ('ipconfig /all^|find /i "ip address"') do @echo %j is your IP address.

  As for "Options", you are right.

 
  You need to experience the usage of this command more to truly master it.


[ Last edited by lxmxn on 2006-10-30 at 06:24 AM ]
Floor 24 Posted 2006-10-30 06:19 ·  中国 河南 南阳 中移铁通
初级用户
Credits 122
Posts 12
Joined 2004-04-24 00:00
22-year member
UID 23125
Gender Male
Status Offline
The meaning of delims is to split and combine the processing results of each loop in the execution statement into a set. Tokens is to take a character obtained by moving a certain step forward at a time? The meaning of "add^|find /i "" in the parentheses of ('ipconfig /add^|find /i "ip address"') I don't understand.

[ Last edited by ghtfuo on 2006-10-30 at 06:21 AM ]
Floor 25 Posted 2006-10-30 07:04 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
19-year member
UID 59080
Status Offline

  Re: ghtfuo

  Oh, sorry, I made a mistake. I've corrected it. Here, "add" should be "all". This "/all" is a parameter of the "ipconfig" command. Its function is to display the detailed information of the current TCP/IP configuration of the computer, including IP, MAC, gateway, and host name, etc. This is in contrast to the situation where the "ipconfig" command has no parameters..

  Here, "('ipconfig /all^|find /i "ip address"')" should be understood in two parts. One is "ipconfig /all", and the other is "find /i "ip address"". The former has been explained above, and the "/i" in the latter is a parameter of the "find" command, which means ignoring case when searching. Let's take an example.
  For example, there is a file abc.txt with the following content:
--------------------abc.txt---------------------------------------------
www.Cn-DoS.net
www.cn-dos.net
--------------------abc.txt---------------------------------------------
There are only these two lines. Then, executing "find "Cn-DoS" abc.txt" in the command prompt can find the content of the first line. If you use "find "cn-dos" abc.txt", you can find the content of the second line. If you use the "/i" parameter, it means ignoring case when searching. So, if you execute "find /i "cn-Dos" abc.txt", then both lines in abc.txt can be found..

  Here, "^|" is the pipe symbol, which functions to transfer the result of "ipconfig /all" to the "find /i "ip address"" command. It can also be understood as taking the result of "ipconfig /all" as the object of the "find /i "ip address"" command. And the "^" symbol here is an escape character. The reason for adding this "^" is determined by the characteristics of the for command. When using the pipe symbol "|" inside the parentheses of the for command, a "^" must be added in front as an escape.

  In addition, it is recommended that you read more of the system's built-in help documents. Or directly view the help with "command /?" in the command line.
hh ntcmds.chm::ntcmds.htm


[ Last edited by lxmxn on 2006-10-30 at 07:30 AM ]
Recent Ratings for This Post ( 1 in total) Click for details
RaterScoreTime
redtek +2 2006-10-30 08:14
Floor 26 Posted 2006-10-30 07:15 ·  中国 河南 南阳 中移铁通
初级用户
Credits 122
Posts 12
Joined 2004-04-24 00:00
22-year member
UID 23125
Gender Male
Status Offline
As soon as you mention it, you'll understand. It's just that this help file can't be found, which is why I'm asking.
Forum Jump: