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

DediPath($1.40),OpenVZ架构 1GB内存

DediPath 商家成立时间也不过三五年,商家提供的云服务器产品有包括KVM和OPENVZ架构的VPS主机。翻看前面的文章有几次提到这个商家其中机房还是比较多的。其实对于OPENVZ架构的VPS主机以前我们是遇到比较多,只不过这几年很多商家都陆续的全部用KVM和XEN架构替代。这次DediPath商家有基于OPENVZ架构提供低价的VPS主机。这次四折的促销活动不包括512MB内存方案。第一、D...

VoLLcloud6折限量,香港CMI云服务器三网直连-200M带宽

vollcloud LLC首次推出6折促销,本次促销福利主要感恩与回馈广大用户对于我们的信任与支持,我们将继续稳步前行,为广大用户们提供更好的产品和服务,另外,本次促销码共限制使用30个,个人不限购,用完活动结束,同时所有vps产品支持3日内无条件退款和提供免费试用。需要了解更多产品可前往官网查看!vollcloud优惠码:VoLLcloud终生6折促销码:Y5C0V7R0YW商品名称CPU内存S...

天上云月付572元,起香港三网CN2直连,独立服务器88折优惠,香港沙田机房

天上云怎么样?天上云隶属于成都天上云网络科技有限公司,是一家提供云服务器及物理服务器的国人商家,目前商家针对香港物理机在做优惠促销,香港沙田机房采用三网直连,其中电信走CN2,带宽为50Mbps,不限制流量,商家提供IPMI,可以自行管理,随意安装系统,目前E3-1225/16G的套餐低至572元每月,有做大规模业务的朋友可以看看。点击进入:天上云官方网站天上云香港物理机服务器套餐:香港沙田数据中...

批处理for为你推荐
manifestedaspphpweb破解painter破解版中文版企业cms企业站cms哪个好magentoMagento是什么flashwind下载了那个FlashWind极速旋风还需要安装吗?怎么安装?怎样使用?360邮箱360免费申请邮箱在那里人人视频总部基地落户重庆2019.5.30号以后重庆有了新的迁入户口政策,请问外省户口以一般人才方式迁入重庆,可以按揭买房吗什么是支付宝支付宝是什么重庆网站制作重庆网站制作哪家好,重庆做网站制作的公司有谁比较了解的,应该去哪里做好些?支付宝注册网站在哪里注册支付宝
哈尔滨域名注册 私服服务器租用 合租服务器 联通vps 美国vps评测 免费动态域名解析 免费域名跳转 cn域名个人注册 冰山互联 美国主机评测 国外bt 美国php主机 长沙服务器 百兆独享 国外代理服务器软件 域名dns ebay注册 工信部icp备案查询 域名转入 登陆qq空间 更多