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

云俄罗斯VPSJusthost俄罗斯VPS云服务器justg:JustHost、RuVDS、JustG等俄罗斯vps主机

俄罗斯vps云服务器商家推荐!俄罗斯VPS,也叫毛子主机(毛子vps),因为俄罗斯离中国大陆比较近,所以俄罗斯VPS的延迟会比较低,国内用户也不少,例如新西伯利亚机房和莫斯科机房都是比较热门的俄罗斯机房。这里为大家整理推荐一些好用的俄罗斯VPS云服务器,这里主要推荐这三家:justhost、ruvds、justg等俄罗斯vps主机,方便大家对比购买适合自己的俄罗斯VPS。一、俄罗斯VPS介绍俄罗斯...

raksmart:年中大促,美国物理机$30/月甩卖;爆款VPS仅月付$1.99;洛杉矶/日本/中国香港多IP站群$177/月

RAKsmart怎么样?RAKsmart发布了2021年中促销,促销时间,7月1日~7月31日!,具体促销优惠整理如下:1)美国西海岸的圣何塞、洛杉矶独立物理服务器低至$30/月(续费不涨价)!2)中国香港大带宽物理机,新品热卖!!!,$269.23 美元/月,3)站群服务器、香港站群、日本站群、美国站群,低至177美元/月,4)美国圣何塞,洛杉矶10G口服务器,不限流量,惊爆价:$999.00,...

美国Cera 2核4G 20元/45天 香港CN2 E5 20M物理机服务器 150元 日本CN2 E5 20M物理机服务器 150元 提速啦

提速啦 成立于2012年,作为互联网老兵我们一直为用户提供 稳定 高速 高质量的产品。成立至今一直深受用户的喜爱 荣获 “2021年赣州安全大赛第三名” “2020创新企业入围奖” 等殊荣。目前我司在美国拥有4.6万G总内存云服务器资源,香港拥有2.2万G总内存云服务器资源,阿里云香港机房拥有8000G总内存云服务器资源,国内多地区拥有1.6万G总内存云服务器资源,绝非1 2台宿主机的小商家可比。...

批处理for为你推荐
操作http中国企业在线如何查询企业是否可靠?补贴eset的是cuteftp腾讯公司电话是多少腾讯公司电话是多少站点管理dreamweaver 合作制作网站站点如何管理zencart模板zen cart套用模板后,外观控制显示红色打不开,为什么?关闭评论怎样关闭评论?无忧验证码手机登录前程无忧怎么不显示登录验证码joomla模板为什么joomla模板安装后跟模板演示的不一样
php网站空间 长沙域名注册 lamp simcentric 加勒比群岛 免费ftp空间 天猫双十一抢红包 免费网站申请 美国十次啦服务器 日本bb瘦 最好的qq空间 免费cdn 搜索引擎提交入口 最漂亮的qq空间 数据库空间 腾讯网盘 国内空间 带宽测试 香港ip godaddy退款 更多