批处理批处理for的变量下(Batch for variables)

批处理for  时间:2021-03-25  阅读:()

批处理for的变量下Batch for variables

Batch: FOR variables (originality)

(two) extended variables

Extended variables can enhance the FOR command. Here is a copyof the official help file.

The replacement of the FOR variable reference has been enhanced.You can now use the following options syntax:

~I - delete any quotes (") . Expand%I

%%~fI - extends%I to a fully qualified path name (full pathn ame)

Only%%~dI - expands%I to a drive letter (letter display only)%%~pI - extends the%I to only one path (only the path isextracted)

%%~nI-extends the%I to only one file name (only the file name)%%~xI - extends the%I to only one file extension (extractingonly the suffix format)

The%%~sI - extended path contains only short names (longf ilenames are reduced)

%%~aI - extends%I to the file properties of the file (a readonly, H hide)

%%~tI - extends%I to the date / time of the file (creation,modification time)

%%~zI - extends%I to the size of the file (KB)

%%~$PATH:I - finds the column in the directory of the pathenvironment variable and extends the%I to the first fullyqualified name found. If the environment variable name is notdefined, or the file is not found, the composite key is expandedto an empty string.

You can combine modifiers to get multiple results:

%%~dpI - extends%I to a drive letter and path only

%%~nxI - extends%I to only one file name and extension%%~fsI - extends only%I to a full pathname with a short name%%~dp$PATH:i - finds the column in the directory of the pathenvironment variable, and extends the%I to the first driveletter and path found.

%%~ftzaI - extend%I to DIR similar to the output lineIn the examples above,%%I and PATH can be replaced by othervalid values. %%~ grammar with a valid variable name FORtermination. Selecting uppercase variable names like%%I iseasier to read and avoid confusing combinations of keys thatare not case sensitive.

When using the FOR command in a batch file, specify variablesusing%%variable instead of%variable. Variable names are casesensitive, so%i is different from%I. At the same time, no morethan 52 are in use.

Many people do not understand the FOR command for officialdocument translation too be beneath the human character. Hereyou just catch the use of the above eleven expansion variables,and the specific role, and so you used, and then check it.1, the use of the option ~I

Example: observe double quotes.

Create text. Delete quote.Txt":

"What' s your name"

"The last name is Zhu, and the name is" Liye ""

"Pig upright leaves?""

"Uh huh!"

"How old is this year?""

"16. "

"January 15, 2009. ""

Ba "____" Ch

"1+1" =?"

''

Code

@echo off

FOR, /F, delims=,%%i, IN (delete quote.Txt) , DO, echo,%%~iPause

Operation result:

1) double quotes in Chinese, none of them disappear. Proof thatit is not valid for double quotation marks in chinese. Such as"16". "

2) the external state of the double quotes English deleted (5to dangerous curtain curtain good song Lai chip H? /span> "1+1""

3) single quotes in English status have not been deleted. Such

Explain:

This command is suitable for extracting strings from otherplaces and deleting the most enclosed double quotes in the

string for other commands. Look at the following example:@echo off

For%%a in ("great Chinese people hooray, hooray, ten millionyears old") do echo.%%~a

Pause>nul

Operation result:

Long live the great Chinese people! Hooray!

Explain:

If you do not use double quotes, you will display them insections. Double quotation marks using Chinese status, withdouble quotation marks. But the double quotation marks ("" """") in English states are very clean.

2, the use of other options

Example: only the file name is checked:

@echo off

For%%i in do echo%%~ni (. *)

Pause>nul

Explain:

%%~ni can extract file names, and using this command to extractsongs from your computer will be the best choice.

Cases:

View date size file name:

@echo off

For%%i in do echo%%~ztni (. *)

Pause>nul

Explain:

Sometimes you want to look at the date, size, property, etc.of a file, and you can use the add in variables together.This might be useful in antivirus.

Although the expansion variables are many, but the usage isbasically the same, they can be replaced by other extendedvariables instead of%%~ni.

Note that the last letter I of the variable is not fixed, whatis the input variable, and what it should be.

For example, using%%~$PATH:I:

@echo off

For /r%%a in do echo%%~$PATH:a (. *)

Pause>nul

Explain:

The first%%a uses a, then the second%%a is still using a, anddoes not change because of the addition of the extended variable~$PATH. Can not be born hard move formula, all use I.Extended environment variables are often used to extract keycharacters, or to exclude other redundant factors.

(three) system variables

(temporarily omitted)

Third section FOR DO

I. overview

DO followed by one or a set of commands. A command that indicatesthe execution of each FOR cycle.

Sometimes the commands behind DO are too complex and need tobe bracketed together to represent a whole.

Two, type

1, an order:

For,%%i, in (. . . , o*.mp3) , do, echo,%%i

2, a set of commands:

For, /r, d: ,%%i, in (QQ.exe) , do, if, exist,%%i, , start,%%i1, need brackets:

@echo off

Color 0A

For, /l,%%a, in (1,2,8) do

For, /l,%%b, in (3, 3, 18) do

For, /l,%%c, in (100, -15,30) do

Echo%%a%%b%%c

)

)

)

Pause

Three, use

(omitted) see the fifth section of the FOR command synthesisapplication

如何低价香港服务器购买?有没有便宜的香港服务器推荐?

如何低价香港服务器购买?想要做一个个人博客,想用香港服务器,避免繁琐备案,性能不需要多高,只是记录一些日常而已,也没啥视频之类的东西,想问问各位大佬有没有低价的香港服务器推荐?香港距大陆近,相比美国服务器最大的优势在于延迟低,ping值低,但是带宽紧张,普遍都是1M,一般戏称其为“毛细血管”。同时价格普遍高,优质稳定的一般价格不菲。大厂云梯队阿里云、腾讯云两家都有香港服务器,要注意的是尽量不要选择...

Gigsgigscloud($9.8)联通用户优选日本软银VPS

gigsgigsCloud日本东京软银VPS的大带宽配置有100Mbps、150Mbps和200Mbps三种,三网都走软银直连,售价最低9.8美元/月、年付98美元。gigsgigscloud带宽较大延迟低,联通用户的好选择!Gigsgigscloud 日本软银(BBTEC, SoftBank)线路,在速度/延迟/价格方面,是目前联通用户海外VPS的最佳选择,与美国VPS想比,日本软银VPS延迟更...

virmach:AMD平台小鸡,赌一把,单车变摩托?$7.2/年-512M内存/1核/10gSSD/1T流量,多机房可选

virmach送来了夏季促销,价格低到爆炸,而且在低价的基础上还搞首年8折,也就是说VPS低至7.2美元/年。不过,这里有一点要说明:你所购买的当前的VPS将会在09/30/2021 ~ 04/30/2022进行服务器转移,而且IP还会改变,当前的Intel平台会换成AMD平台,机房也会变动(目前来看以后会从colocrossing切换到INAP和Psychz),采取的是就近原则,原来的水牛城可能...

批处理for为你推荐
平阴县教育和体育局下属锦东小学教学设备采购项目竞争性磋商文件我爱试用网电信爱玩4G定向流量包开通需要交费吗什么是seoSEO网站优化是什么啊?qq头像上传失败昨天和今天QQ头像上传失败,是怎么回事?团购程序什么是团购 团购的目的与流程dedecms采集织梦后台怎么采集图片广告后台我是卖家,淘宝上买家评价中的广告和图片后台可以删除吗?论坛版块图标论坛版块图标怎么设置?放图片的链接吗?还是?网页计数器怎么用DW做网页计数器站长统计【求站长统计工具CNZZ的详细使用方法】
购买域名 企业主机 国外永久服务器 cloudstack 免费ftp空间 tightvnc ev证书 个人免费空间 777te 双拼域名 阿里校园 100mbps 江苏双线服务器 starry cxz 数据库空间 西安主机 黑科云 netvigator 七十九刀 更多