中国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-11 09:46
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Please clarify the context. The provided "for语句中的delims=" , " is a partial content. Could you provide more relevant information to accurately translate and explain?
Printable Version  1,515 / 7
Floor1 26933062 Posted 2006-12-24 06:16
银牌会员 Posts 879 Credits 2,268
The following is the translation:

Regarding the part where delims= in the content, if it is delims=\" I know that \ is used as the delimiter, but what does it mean when there is nothing behind it? I can't figure it out. Hope an expert can explain. Also, please explain the red parts for me? Please.
@echo off&setlocal EnableDelayedExpansion
set a=1
for /f "delims=%%i in ('dir /a-d/b/s *.txt') do (
if not "%%~ni"=="%~n0"
!%%~xi"
set/a a+=1
)


Explanation of red parts:
- "delims=": In the for /f command, delims is used to specify the delimiter. When delims is set to an empty value, it means using the default delimiters, which are spaces, tabs, etc.
- "if not "%%~ni"=="%~n0"": It is an if condition judgment. %%~ni is the name of the current loop variable i, and %~n0 is the name of the current batch file without the extension. It is judging whether the name of the current loop variable i is not equal to the name of the current batch file without the extension.
- "%%~ni!a!%%~xi": %%~ni is the name of the current loop variable i without the extension,!a! is the value of variable a, %%~xi is the extension of the current loop variable i. So it is renaming the file to the name without extension + value of variable a + extension.
Floor2 lxmxn Posted 2006-12-24 06:28
版主 Posts 4,938 Credits 11,386

  Re 26933062 :

  The delims in the for specifies the delimiter. Here, no delimiter is specified, which means no character is a delimiter, and then it means taking the entire content of a line, regardless of any symbols in it.

  For %%~ni, refer to the for help command, which is there.
Floor3 26933062 Posted 2006-12-24 06:36
银牌会员 Posts 879 Credits 2,268
lxmxn
Thank you in advance for your answer,
If that's the case then I might as well not write it, right? Like the following content, is there anything wrong with it?
I tried it, the program runs normally, just don't know if it will have problems in some other environment.
Also, for the red part, why use only a single % sign?
@echo off&setlocal EnableDelayedExpansion
set a=1
for /f %%i in ('dir /a-d/b/s *.txt') do (
if not "%%~ni"=="%~n0" (
ren "%%i" "%%~ni!a!%%~xi"
set/a a+=1
)
)
Floor4 lxmxn Posted 2006-12-24 08:00
版主 Posts 4,938 Credits 11,386

  Re 26933062 :

  If you remove the delims option, when the file contains symbols such as spaces, the program may not achieve the effect you want or even cause errors.

  The %~n0 in the red part represents the file name of the batch processing itself, so this batch processing itself will not be renamed.
Floor5 namejm Posted 2006-12-24 11:07
荣誉版主 Posts 1,737 Credits 5,226 From 成都
In the for /f statement, by default, spaces or tabs (that is, the character produced by pressing the tab key which is 8 spaces) are used as delimiters. If the value of delims is not specified, it means that spaces or tabs are used as delimiters.
Floor6 26933062 Posted 2006-12-24 13:12
银牌会员 Posts 879 Credits 2,268
Floor7 earth123xinyuan Posted 2009-02-11 03:02
社区乞丐 Posts 25 Credits -46 From 内蒙
I sort of understand, but not completely. I'll learn it step by step.
Floor8 5yue5 Posted 2009-02-15 22:30
初级用户 Posts 34 Credits 69
Go to see the example here
http://www.cn-dos.net/forum/viewthread.php?tid=46126&fpage=2
"delims="
The content of the text file is divided into several segments by each line by for. The symbol for segmenting is called a delimiter, and the system default is a space.
delims means define limite to define the boundary. "delims= " means that the delimiter is a space symbol to divide each line into several segments. This is the system default, and at this time, you can not have delims=space, which is also the same. If this sentence is changed to delims=k, each line will be divided into several segments according to the letter k. for by default only captures the first segment of each line into memory for operation.
For example, the content of *.txt is
11 12 13
21 22 23
31 32 33
Then what for captures is
11
21
31
Special note: This for will not capture the entire line of data. It will only capture the first segment of each line! If you want for to capture the entire line of data, you have to add a disruptor, that is, tokens=*
”%%~ni“
Here n comes from the English name, which means name. The ~ symbol represents removing the double quotes. So "%%~ni" means to expand the file name read by parameter %%i. How to expand? For example, if %%i represents the file name 123456.txt, then %%~ni represents: 123456
And %%~xi represents:.txt (x is the meaning of extended)
if not "%%~ni"=="%~n0" is: if the file name obtained from %%~ni from %i is not equal to the file name obtained from %~n0 from %0 (without extension), then what.

[ Last edited by 5yue5 on 2009-2-15 at 22:56 ]
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023