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

RFCHOST - 洛杉矶CN2 GIA VPS季付23.9美元起 100Mbps带宽

RFCHOST,这个服务商我们可能有一些朋友知道的。不要看官网是英文就以为是老外服务商,实际上这个服务商公司在上海。我们实际上看到的很多商家,有的是繁体,有的是英文,实际上很多都是我们国人朋友做的,有的甚至还做好几个品牌域名,实际上都是一个公司。对于RFCHOST商家还是第一次分享他们家的信息,公司成立大约2015年左右。目前RFCHOST洛杉矶机房VPS正进行优惠促销,采用CN2优化线路,电信双...

香港服务器促销:香港华为云混合服务器、高防服务器首月半价,普通110M大带宽服务器月付799,付5用6,付10用13

博鳌云是一家以海外互联网基础业务为主的高新技术企业,运营全球高品质数据中心业务。自2008年开始为用户提供服务,距今11年,在国人商家中来说非常老牌。致力于为中国用户提供域名注册(国外接口)、免费虚拟主机、香港虚拟主机、VPS云主机和香港、台湾、马来西亚等地服务器租用服务,各类网络应用解決方案等领域的专业网络数据服务。商家支持支付宝、微信、银行转账等付款方式。目前香港有一款特价独立服务器正在促销,...

舍利云30元/月起;美国CERA云服务器,原生ip,低至28元/月起

目前舍利云服务器的主要特色是适合seo和建站,性价比方面非常不错,舍利云的产品以BGP线路速度优质稳定而著称,对于产品的线路和带宽有着极其严格的讲究,这主要表现在其对母鸡的超售有严格的管控,与此同时舍利云也尽心尽力为用户提供完美服务。目前,香港cn2云服务器,5M/10M带宽,价格低至30元/月,可试用1天;;美国cera云服务器,原生ip,低至28元/月起。一、香港CN2云服务器香港CN2精品线...

批处理for为你推荐
yw372:ComIE主页被修改为http://www.hao372.com/ 桌面上的IE图标还变成了两个googlepr值如何提高Google PR值?中国企业在线有什么B2B网站可以做国外的?多给些。。回答的好追加企业信息查询系统官网怎么查企业信息是否在网上公示过期刊eset加多宝和王老吉王老吉和加多宝的区别curl扩展系统不支持CURL 怎么解决免费代理加盟怎样免费加盟代理淘宝美国独立美国独立的意义社区动力如何大力加强社区基层党组织建设
域名服务器上存放着internet主机的 服务器评测 payoneer 双12活动 xen java虚拟主机 架设服务器 河南m值兑换 umax120 服务器监测 上海服务器 优酷黄金会员账号共享 web服务器搭建 数据库空间 云服务器比较 万网空间 中国联通宽带测试 云服务是什么意思 广州主机托管 博客域名 更多