批处理批处理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

IonSwitch:$1.75/月KVM-1GB/10G SSD/1TB/爱达荷州

IonSwitch是一家2016年成立的国外VPS主机商,部落上一次分享的信息还停留在2019年,主机商提供基于KVM架构的VPS产品,数据中心之前在美国西雅图,目前是美国爱达荷州科德阿伦(美国西北部,西接华盛顿州和俄勒冈州),为新建的自营数据中心。商家针对新数据中心运行及4号独立日提供了一个5折优惠码,优惠后最低1GB内存套餐每月仅1.75美元起。下面列出部分套餐配置信息。CPU:1core内存...

简单测评melbicom俄罗斯莫斯科数据中心的VPS,三网CN2回国,电信双程cn2

melbicom从2015年就开始运作了,在国内也是有一定的粉丝群,站长最早是从2017年开始介绍melbicom。上一次测评melbicom是在2018年,由于期间有不少人持续关注这个品牌,而且站长貌似也听说过路由什么的有变动的迹象。为此,今天重新对莫斯科数据中心的VPS进行一次简单测评,数据仅供参考。官方网站: https://melbicom.net比特币、信用卡、PayPal、支付宝、银联...

Spinservers:美国圣何塞机房少量补货/双E5/64GB DDR4/2TB SSD/10Gbps端口月流量10TB/$111/月

Chia矿机,Spinservers怎么样?Spinservers好不好,Spinservers大硬盘服务器。Spinservers刚刚在美国圣何塞机房补货120台独立服务器,CPU都是双E5系列,64-512GB DDR4内存,超大SSD或NVMe存储,数量有限,机器都是预部署好的,下单即可上架,无需人工干预,有需要的朋友抓紧下单哦。Spinservers是Majestic Hosting So...

批处理for为你推荐
internalservererrorinternal server error怎么解决wordpress模板wordpress的模版怎么用支付宝调整还款日花呗调整还款日算延期吗?dell服务器bios设置dell怎样进入bios设置界面人人视频总部基地落户重庆渝洽会上的西部国际总部基地是做什么的?flashftp下载《蔓蔓青萝(全)》.TXT_微盘下载verticalflash资费标准中国移动38元套餐介绍tumblr上不去吃鸡更新完打不开,成这样了,怎么办在线等,挺急的青岛网通测速家用电脑上网(青岛网通)512k网速算不算快,玩主流网游卡不卡
域名查询系统 vps优惠码cnyvps 免费二级域名申请 西安电信测速 ion 美元争夺战 哈喽图床 商务主机 双线主机 免费防火墙 电信虚拟主机 ftp免费空间 域名与空间 英雄联盟台服官网 中国联通宽带测速 杭州电信宽带 香港博客 alexa世界排名 ipower nic 更多