当前位置:文档之家› UE宏命令自动批处理替换文本

UE宏命令自动批处理替换文本

UE宏命令自动批处理替换文本
UE宏命令自动批处理替换文本

UE宏命令自动批处理替换文本

[免费下载]

在文本编辑过程中,经常有某项工作要多次重复(如连续遍历N次替换文本),这时可以利用UE的宏功能来使其自动执行,以提高效率。宏是将一系列的UE命令和指令组合在一起,形成一组“批处理”命令,以实现任务执行的自动化。

1.“宏”菜单>>“录制”>>在弹出的对话框中设定快捷键。

2.如作查找替换操作,把替换窗口关掉。

3.在“宏”菜单,选“停止录制”。关闭UE时间会提示是否保存宏。

4.宏”菜单,选“自动加载宏”,设置每次启动自动加载指定宏,只要启动了UE按下快捷键(如Ctrl+M),即自动批处理。

解释版(录制后将得到如下类似宏,但没有此处复杂):

**Mode //使用**模式

ColumnModeOff //关闭列模式

HexOff //关闭十六进制模式

Find RegExp "^interface Port-channel?" //使用正则表达式查找关键字,关键字格式为:

//行首以interface Port-channel打头的,后面的?表示匹配除换行符外的任一单个//字符,因为可能是Port-channel1也可能是Port-channel2,所以用?表示

IfFound //若找到

Key RIGHT ARROW //光标向右移一个字符

Start** //开始选择

Loop 4 //循环4次

Key RIGHT ARROW //也就是向右移动4个字符

EndLoop

End** //选择4个字符,也就是VLAN ID

Copy //复制VLAN ID到剪贴板

Key DOWN ARROW //向下移动两行

Key DOWN ARROW

Key HOME //光标移到行首

"encapsulation dot1Q " //输入"encapsulation dot1Q ",注意后有个空格

Paste //复制剪贴板中的VLAN ID到dot1Q 后面,从而实现VLAN ID的复制

" //两行的双引号,实现换行

"

EndIf

如做查找替换文本,以上录制时第一步请先按Ctrl+Home将光标定位到第一行行首,查看宏可以看到增加了Top命令,这在自动批处理替换过程相当重要,至于作用自己去悟,先不要这么做失败了再去这么做了我想你会感谢我。

附:

本文作者fashio7752的百度知道相关回答:

ue中的$如何去掉

https://www.doczj.com/doc/71532893.html,/question/231444929.html?oldq=1

技巧版:

1. UE里面替换tab键为空格

解决使用UE编辑好且排列整齐的文件在EditPlus中错位的问题。

对于已有的带有tab键的空格,若需要将tab键转换为空格,可使用如下方法:

1)使用查找替换功能(Ctrl+R),^t 表示tab,在出现的窗口中的“查找(N)”输入:^t ,“替换为(P)”输入四个空格,全部替换即可。

2)中文是工具栏“格式”->“转换制表符为空白”

英文是工具栏“format”->“tab to spaces”。

若要使新建的文件在UE中编辑时,键入tab键时为4个空格,可选择工具栏选择“高级”->“配置”,勾选“用空格代替制表符”,并将缩进的空格由2改成4即

正则表达式( Syntax):

% 匹配行首- 表明要搜索的字符串一定在行首.

$ 匹配行尾- 表明要搜索的字符串一定在行尾

? 匹配除换行符外的任一单个字符.

* 匹配任意个数的字符出现任意次数(不包括换行符)

+ 匹配前导字符或者表达式出现一次或者更多次(不包括换行符)

++ 匹配前导字符或者表达式不出现或者出现一次以上(不包括换行符)

^b 匹配页中断符

^p 匹配DOS文件的换行符

^r 匹配MAC文件的换行符(CR Only)

^n 匹配UNIX文件的换行符(LF Only)

^t 匹配一个制表符

[ ] 匹配方括号中的单个的字符

删除空行: 替换%[ ^t]++^p 为空串

删除行尾空格: 替换[ ^t]+$ 为空串

删除行首空格: 替换%[ ^t]+ 为空串

每行设置为固定的4个空格开头: 替换%[ ^t]++^([~ ^t^p]^) 为" ^1"

每段设置为固定的4个空格开头: 替换%[ ^t]+ 为" "

(如果一行是以空格开始的,则视之为一段的开始行)

将一段合并为一行: 替换[ ^t]++^p^([~ ^t^p]^) 为^1

(注意: 此处假定文本是以DOS方式回车换行- CR/LF)

去掉HTML TAG: 替换^{<*>^}^{<*^p*>^} 为空串

删除HTML中的所有: 替换<[ ]++a *[ ]++href[ ]++=*> 为空串

删除文本中指定的前2列字符: 替换%?? 为空串

在第4列后插入2列空白字符: 替换%^(????^)^(?^) 为"^1 ^2"

查找所有的数字: [0-9]+[.]++[0-9]+

查找所有的单词: [a-z]+

查找所有的网址: http://[a-z0-9^~`_./^-^?=&]+

UltraEdit 宏编辑命令汇总

UltraEdit 10.0 帮助文件

Edit Macro (Macro menu)

The Edit Macro command allows a new macro to be created and edited or an

existing macro that has previously been generated with this command or with

the Macro Record command to be edited.

In many cases, it is easier for the user to generate the macro by recording

it with the Macro Record command and then to edit it if necessary. The learning curve is less with this approach.

Commands

A macro is a series of commands that may later be played back automatically

to modify the file. The left hand side of the dialog shows the current macro being edited and an editable window containing the commands that make

up the macro.

The commands in the macro must be one of the predefined commands. These

predefined commands are shown on the right hand side of the dialog. If the

mouse is double clicked on the command it is automatically added to the macro, or clicking on the arrow to the left of the commands will add it to the macro.

Parameters

Many of the commands have numeric parameters. The numeric parameters are

quite obvious, such as "Goto Line #" or "Goto Page #". However, some of the

commands such as Find and Replace, Sort etc. have additional parameters

that are not numeric. These additional parameters are listed below the

command list for easy selection.

Creating a New Macro

To create a new macro from this dialog click the New/Macro button.

This

displays the Macro Definition dialog allowing you to define the macro name

and hot key if required.

When this new macro is created, three macro commands are automatically added

to the macro:

- Insert Mode or OverStrike Mode

- ColumnModeOn or ColumnMode Off

- HexOn or HexOff

These three commands are added based on the current state of the editor.

The purpose is to establish a known state each time the macro is played. If

a macro is recorded in one mode and played back in another the results may

be unpredictable. Establishing the mode at the beginning of the macro helps

to ensure the expected results are achieved. These commands may be modified as required.

Once an edit macro has been created, it may be edited.

Modifying The Macro

To modify the macro, commands may be typed directly into the macro edit box

or selected from the command list. Commands are not case sensitive but must

be spelled exactly as shown in the command list.

The table below shows the commands that may be added to any parameters:

Commands Parameters* Description

1. ""Insert text between the quotes (""). The closing

2. quote must be the last non-space character on the line. The

characters to

3. be inserted may cross multiple lines. To insert a quote ("),

place it as

4. needed in the text being inserted and ensure the last character is

also a

5. quote. To insert just one quote character (") the line should

look like

6. this:"""To insert a new line, add a line between the open quote

and close

7. quote. To insert two lines with 1 and 2 at the beginning of the

lines the

8. command should be as follows:

9. "1

10. 2"

11.

12.

13. AnsiToOem Convert file from ANSI to OEM.

14.

15.

16. Bottom Jump to end of file.

17.

18.

19. CloseFile Blank (no parameter),Save - forces the file to be

20. saved before closingNoSave ?closes the file without prompting

if the file

21. should first be saved Close the active file.

22.

23.

24. ClearClipboard Clear the contents of the active

25. clipboard within UltraEdit.

26.

27.

28. Clipboard Clipboard number (0-9) Select the specified

29. clipboard ?0 = Windows Clipboard and 1-9 specifies user

clipboards.

30.

31.

32. ColumnCenterJustify Center justify selected columns.

33.

34.

35. ColumnLeftJustify Left justify selected columns.

36.

37.

38. ColumnRightJustify Right justify selected columns.

39.

40.

41. ColumnModeOff Turn the column mode off.

42.

43.

44. ColumnModeOn Turn the column mode on.

45.

46.

47. ColumnCut Cut selected columns in column mode.

48.

49.

50. ColumnDelete Delete selected columns in column

mode.

51.

52.

53. ColumnInsert String in quotes ("") Insert string between

quotes

54. into selected columns.

55.

56.

57. ColumnInsertNum start numberincrementLeadingZero

(optionally)

58. Insert number in selected columns.

59.

60.

61. Copy Copy selected text to the clipboard.

62.

63.

64. CopyAppend Copy selected text and append it to the

65. clipboard.

66.

67.

68. CopyFilePath Copy the active file path/name to the

69. clipboard.

70.

71.

72. Cut Cut the selected text from the file to the

clipboard.

73.

74.

75. CutAppend Cut the selected text from the file and

76. append it to the clipboard.

77.

78.

79. Delete Delete current character or selected text.

80.

81.

82. DeleteLine Delete the current line.

83.

84.

85. DeleteToEndofLine Delete from the current cursor

86. position to the end of the line.

87.

88.

89. DeleteToStartofLine Delete from the current cursor

90. position to the start of the line.

91.

92.

93. DosToMac Convert the file (line terminators) to MAC

94. format.

95.

96.

97. DosToUnix Convert the file (line terminators) to

UNIX

98. format.

99.

100.

101. Else Else function for an IF?command.IfSel匛lsedo these

102. commands if the IfSel failed.Endif

103.

104.

105. EndIf Ends the block of instructions controlled by

106. the IfFound/IfNotFound statements.

107.

108.

109. EndLoop End of loop - go back to beginning of the 110. loop - see the Loop command.

111.

112.

113. EndSelect Stop Selecting Text (see Start Select for 114. details).

115.

116.

117. ExitLoop Exit loop and go to first command after the

118. loop (after the EndLoop command) - see the Loop command. 119.

120.

121. ExitMacro Exit Macro without processing any additional

122. commands or returning an error.

123.

124.

125. Find"" (Search string in quotes)MatchCase ?indicates the search

126. is case sensitive (optional)MatchWord - indicates the search string will

127. only match instances that are a complete word (optional)RegExp - Indicates a

128. Regular Expression search (optional)Up - Indicates search in reverse

129. direction (optional)Select ?Indicates the text should be selected from the

130. current selection/position to the end of the search target.

Find the

131. string in quotes "" based on the parameters specified.

132.

133.

134. GetString String in quotes ("") used in the prompt dialog 135. Prompts the user for a string that is inserted in the file at the current

136. location. The "prompt" is the prompt or question that is displayed to the

137. user when the macro is run.GetString "Where country do you live in?"

138.

139.

140. GetValue String in quotes ("") used in prompt dialog 141. Prompts the user for a value that is inserted in the file at the current

142. location. The "prompt" is the prompt or question that is displayed to the

143. user when the macro is run.GetValue "How old are you? " 144.

145.

146. GotoBookMark Jump to the next bookmark.

147.

148.

149. GotoBookMarkSelect Jump to the next bookmark and select

150. text from cursor position to bookmark.

151.

152.

153. GotoLine Numeric value of line number to jump Jump to 154. specified line number.

155.

156.

157. GotoLineSelect Numeric value of line number to jump Jump 158. to specified line number and select text from cursor position to line.

159.

160.

161. GotoPage Numeric value of page to jump Jump to specified

162. page number.

163.

164.

165. GotoPageSelect Numeric value of page to jump Jump to 166. specified page number and select text from cursor position to page number.

167.

168.

169. HexDelete Numeric value specifying number of bytes to delete

170. Delete the specified number of bytes from the file.

171.

172.

173. HexInsert Numeric value specifying number of bytes to insert

174. Insert the specified number of bytes into the file.

175.

176.

177. HexOff Turn Hex mode off - switch to text mode.

178.

179.

180. HexOn Turn Hex mode on.

181.

182.

183. HideOrShowLines Hide the selected lines, or if 184. hidden, show the lines hidden at the line of the cursor.

185.

186.

187. IfCharGt "character" or number.This checks if the current

188. character at the cursor position is greater than the specified character or

189. number specified. The check against a number is not to check the value of a

190. string but the value of the underlying character.IfCharGt " "?do these

191. commands if the current character is greater than a space.匛ndIfIfCharIs 32?

192. do these commands if the current character抯decimal value is greater than

193. 32 - a space.匛ndIf

194.

195.

196. IfCharIs "string" or number.This checks if the current character

197. at the cursor position is in the specified string, or matches the decimal

198. number.IfCharIs "xyz"?do these commands if the current character is x, y, or

199. z.匛ndIfIfCharIs 34?do these commands if the current character is decimal

200. value 34 - a double quote.匛ndIf

201.

202.

203. IfColNum number. This checks if the current cursor position

204. is the specific column number.IfColNum 10?do these commands if the current

205. cursor position is column 10. Column 1 is the first column.匛ndIf

206.

207.

208. IfColNumGt number. This checks if the current cursor position

209. is greater than the specific column number.IfColNumGt 10?do these commands

210. if the current cursor position is greater than column 10.

Column 1 is the

211. first column.匛ndIf

212.

213.

214. IfEof This checks if the current cursor position

215. is at the end of file.IfEof?do these commands if at end of file匛ndIf

216.

217.

218. IfExtIs "string".This checks if the file extension of the 219. active file matches the specified string. If the extension matches, the

220. condition is satisfied and the macro will execute the steps following the

221. IfextIs statement.IfExtIs "txt"?do these commands if the current file

222. extension is txt.匛ndIf

223.

224.

225. IfFound This checks the results from the last find

226. command in the macro and will execute the next set of instructions up to an

227. "EndIf" if the last search was successful:Find

"something"IfFound?do these

228. commands if "something" was found匛ndIfNOTE - To avoid a "Not Found" message

229. when running the macro, make sure the "Continue if a Find with Replace Not

230. Found" check box is set for the macro properties.

231.

232.

233.

234. IfFTP This checks if the current file is a file

235. loaded via FTP/SFTP and not a local/network file.IfFTP?do these commands if

236. the file is an FTP loaded file匛ndIf

237.

238.

239. IfNameIs "string".This checks if the active filename (not path

240. or extension) matches the specified string. If the name matches, the

241. condition is satisfied and the macro will execute the steps following the

242. IfNameIs statement.IfNameIs "test"?do these commands if the current filename

243. is test (irrespective of the file extension).匛ndIf

244.

245.

246. IfNotFound This checks the results from the last find 247. command in the macro and will execute the next set of instructions up to an

248. "EndIf" if the last search was NOT successful:Find "something"IfNotFound?do

249. these commands if "something" was NOT found匛ndIfNOTE - To avoid a "Not

250. Found" message when running the macro, make sure the "Continue if a Find

251. with Replace Not Found" check box is set for the macro properties.

252.

253.

254. IfSel This checks if there is currently any

255. selected text within the active file.IfSel?do these commands if "something"

256. is selected匛ndIf

257.

258.

259. InsertMode Change text editing mode to insert mode for

260. characters typed.

261.

262.

263. InsertPageBreak Insert a form feed/page break 264. character at the current cursor position in the file.

265.

266.

267. InvertCase Invert the case of selected text.

268.

269.

270. Loop x Loop x times where x is a number. A value of 0 271. indicates Loop forever.i.e.Loop 10?do these commands 10 times 匛ndLoop

272.

273.

274. Key BackspaceCtrl+DELDOWN ARROWENDHOMELEFT ARROWPGDNPGUPRIGHT

275. ARROWUP ARROW Insert a key command into the macro.

Generally used for

276. navigation in the file and for backspace or delete. The "Ctrl+"

modifier

277. may be used as with normal editing to modify the command.For text input the

278. "" string command is used, not the Key command.

279.

280.

281. MatchBrace Find matching brace and select the text 282. between them.

283.

284.

285. NextWindow Switch to next window.

286.

287.

288. NewFile Open a new blank file.

289.

290.

291. OemToAnsi Convert file from OEM to ANSI.

292.

293.

294. Open Filename in quotes ("") Open the specified file. The 295. Filename must be in quotes. "^s" may be used in the filename.

UltraEdit

296. will replace this with the currently selected text in the active Window.

297. Likewise, "^c" may be used and UltraEdit will replace this with the contents

298. of the clipboard.

299.

300.

301. OverStrikeMode Change text editing mode to 302. overstrike mode for characters typed.

303.

304.

305. Paste Paste the contents of the clipboard into the 306. file.

307.

308.

309. PlayMacro Numeric value specifying number of times to play

310. itMacro name ("") in quotes. Play another macro. Specify the number of

311. times to play the macro first, then the macro name. The macro name must be

312. in quotes.

313.

314.

315. PreviousBookMark Jump to the previous bookmark. 316.

317.

318. GotoBookMarkSelect Jump to the previous bookmark and

319. select text from cursor position to bookmark.

320.

321.

322. PreviousWindow Switch to previous window. 323.

324.

325. Replace All - Replace all occurrences.AllFiles - Replace in all

326. open files (requires All).Selected Text ?Replace in selected text (Requires

327. All).Replace String in quotes ("") - String to replace the found string.

328. The Replace command replaces the previously found string with the

329. string specified. This command MUST follow a Find command.As with the Find

330. string, the replace string must be in quotes. The closing quote must be the

331. last non-space character on the line.The replace string may cross multiple

332. lines however, if the last non-space character in any line is a quote it

333. will terminate the string. All special characters permitted by the Replace

334. Command are permitted here.

335.

336.

337. ReturnToWrap Convert hard returns to word wrap. 338.

339.

340.

341. RunTool String in quotes ("") specifying the menu name of

342. tool to run Run a tool. The tool must be configured from Tool

343. Configuration in the Advanced menu.

344.

345.

346. Save Save active file.

347.

348.

349. SaveAll Save all open files.

350.

351.

352. SaveAs Filename in quotes ("") Save the active file as the

353. filename specified. The Filename must be in quotes. "^s" may be used in the

354. filename. UltraEdit will replace this with the currently selected text in

355. the active Window. Likewise, "^c?may be used and UltraEdit will replace

356. this with the contents of the clipboard.

357.

358.

359. SelectAll Select all text in the file.

360.

361.

362. SelectToBottom Select all text from the current 363. position to the end of file.

364.

365.

366. SelectToTop Select all text from the current position to

367. the top of file.

368.

369.

370. SelectWord Select the current word (same as double 371. clicking a word).

372.

373.

374. SortAsc IgnoreCase - Ignore case of characters in the sort.

375. RemoveDup - Remove duplicate lines.Numeric ?Sort based on numeric value, not

376. character orderPairs of sort keys (numeric values), each value is separated

377. by a space. Sort the file, or selected text in ascending order. 378.

379.

380. SortDes IgnoreCase ?Ignore case of characters in the sort.

381. RemoveDup ?Remove duplicate lines.Numeric ?Sort based on numeric value, not

382. character orderPairs of sort keys (numeric values), each value is separated

383. by a space. Sort the file, or selected text in descending order.

384.

385.

386. SpacesToTabs Convert (leading) spaces within the file to

387. tabs.

388.

389.

390. SpacesToTabsAll Convert (all) spaces within the file

391. to tabs.

392.

393.

394. StartSelect Start selection. This turns the selection 395. mode on. Any cursor movement or positioning will be with selection on and

396. the text is selected. EndSelect will stop the selection mode.

The selected

397. text will remain selected until another command causes it not to be

398. selected as with normal editing.

399.

400.

401. TabsToSpaces Convert all tabs within the file to spaces. 402.

403.

404. Template Template Number (#) Insert the specified 405. template into the file.

406.

407.

408. TimeDate Insert the time and date into the file at 409. the current location.

410.

411.

412. ToCaps Capitalize each word in the selected text.

413.

414.

415. ToggleBookMark Set or remove a bookmark at the 416. current line.

417.

418.

419. ToLower Convert the selected text to lower case. 420.

421.

422. Top Jump to top of file.

423.

424.

425. ToUpper Convert the selected text to upper case. 426.

427.

428.

429. TrimTrailingSpaces Trim trailing spaces from each line

430. of current file.

431.

432.

433. UnixMactoDos Convert the active file (line terminators) 434. from Mac/Unix to DOS format.

435.

436.

437. UnixReOff Switch regular expressions to UltraEdit 438. style regular expressions (not Unix).

439.

440.

441. UnixReOn Switch regular expressions to Unix style 442. regular expressions.

443.

444.

445. WrapToReturn Column number (#) at which wrap is

performed.Zero

446. for the column number indicates the wrap is to occur at the window boundary.

447. Convert the file from word wrap to hard returns.

448.

* Where (#) exists in the parameter column a numeric value is to be entered

for that parameter. Likewise, where ("") exists in the parameter column a stringis to be entered between quotes. The text only describes the meaning

of the parameter. All string parameters must be the last parameter.

DOS批处理脚本

DOS批处理脚本 这是一篇技术教程,真心诚意会用很简单的文字表达清楚自己的意思,只要你识字就能看懂,就能学到知识。写这篇教程的目的,是让每一个看过这些文字的朋友记住一句话:如果爱可以让事情变的更简单,那么就让它简单吧!看这篇教程的方法,就是慢!慢慢的,如同品一个女人、一杯茗茶,你会发现很多以前就在眼前的东西突然变的很遥远,而有些很遥远的东西却又突然回到了眼前。. 先概述一下批处理是个什么东东。批处理的定义,至今我也没能给出一个合适的----众多高手们也都没给出----反正我不知道----看了我也不一定信服----我是个菜鸟,当然就更不用说了;但我想总结出一个“比较合适的”,而且我也相信自己可以把它解释的很清楚,让更多的菜鸟都知道这是个什么东东,你用这个东东可以干什么事情。或许你会因为这篇文章而“无条件爱上批处理”,那么我的目的就达到了----我就是要让你爱上它,我就这么拽,你能怎么着??真的,爱有时候就这么拽,就是这么没理由,就是这么不要脸!真的! 按照我的理解,批处理的本质,是一堆DOS命令按一定顺序排列而形成的集合。 OK,never claver and get to business(闲话少说言归正传)。批处理,也称为批处理脚本,英文译为BATCH,批处理文件后缀BAT就取的前三个字母。它的构成没有固定格式,只要遵守以下这条就ok了:每一行可视为一个命令,每个命令里可以含多条子命令,从第一行开始执行,直到最后一行结束,它运行的平台是DOS。批处理有一个很鲜明的特点:使用方便、灵活,功能强大,自动化程度高。我不想让自己写的教程枯燥无味,因为牵缠到代码(批处理的内容算是代码吧?)的问题本来就是枯燥的,很少有人能面对满屏幕的代码而静下心来。所以我会用很多简单实用的例子让读这篇教程的朋友去体会批处理的那四射的魅力,感受它那古灵精怪的性格,不知不觉中爱上批处理(晕,怎么又是爱?到底批处理和爱有什么关系?答案:没有!)。再说句“闲话”:要学好批处理,DOS基础一定要牢!当然脑子灵活也是很重要的一方面。 例一、先给出一个最easy的批处理脚本让大家和它混个脸熟,将下面的几行命令保存为name.bat然后执行(以后文中只给出代码,保存和执行方式类似): ping https://www.doczj.com/doc/71532893.html, > a.txt ping https://www.doczj.com/doc/71532893.html, >> a.txt ping https://www.doczj.com/doc/71532893.html, >> a.txt ping https://www.doczj.com/doc/71532893.html, >> a.txt ping https://www.doczj.com/doc/71532893.html, >> a.txt

批处理基础知识

批处理文件基础知识 一、单符号message指定让MS-DOS在屏幕上显示的正文 ~ ①在for中表示使用增强的变量扩展。 ②在%var:~n,m%中表示使用扩展环境变量指定位置的字符串。 ③在set/a中表示一元运算符,将操作数按位取反。 ! ①在set /a中一元运算符,表示逻辑非。比如set /a a=!0,这时a就表示逻辑1。 @ ①隐藏命令行本身的回显,常用于批处理中。 % ①在set /a中的二元运算符,表示算术取余。 ②命令行环境下,在for命令in前,后面接一个字符(可以是字母、数字或者一些特定字符),表示指定一个循环或者遍历指标变量。 ③批处理中,后接一个数字表示引用本批处理当前执行时的指定的参数。 ④其它情况下,%将会被脱去(批处理)或保留(命令行) ^ ①取消特定字符的转义作用,比如& | > < ! "等,但不包括%。比如要在屏幕显示一些特殊的字符,比如> >> | ^ &等符号时,就可以在其前面加一个^符号来显示这个^后面的字符了,^^就是显示一个^,^|就是显示一个|字符了; ②在set/a中的二元运算符,表示按位异或。 ③在findstr/r的[]中表示不匹配指定的字符集。 & ①命令连接字符。比如我要在一行文本上同时执行两个命令,就可以用&命令连接这两个命令。 ②在set/a中是按位与。 : ①标签定位符,表示其后的字符串为以标签,可以作为goto命令的作用对象。比如在批处理文件里面定义了一个":begin"标签,用"goto begin"命令就可以转到":begin"标签后面来执行批处理命令了。 ②在%var:string1=string2%中分隔变量名和被替换字串关系。 | ①管道符,就是将上一个命令的输出,作为下一个命令的输入."dir /a/b |more"就可以逐屏的显示dir命令所输出的信息。 ②在set/a中的二元运算符,表示按位或。 ③在帮助文档中表示其前后两个开关、选项或参数是二选一的。 / ①表示其后的字符(串)是命令的功能开关(选项)。比如"dir /s/b/a-d"表示"dir"命令指定的不同的参数。 ②在set/a中表示除法。 > ①命令重定向符,将其前面的命令的输出结果重新定向到其后面的设备中去,后面的设备中的内容被覆盖。比如可以用"dir > lxmxn.txt"将"dir"命令的结果输出到"lxmxn.txt"这个文本文件中去。 ②在findstr/r中表示匹配单词的右边界,需要配合转义字符\使用。 < ①将其后面的文件的内容作为其前面命令的输入。 ②在findstr/r中表示匹配单词的左边界,需要配合转义字符\使用。 . ①在路径的\后紧跟或者单独出现时:

批处理各符号的功能

是打开地即显当前文件地路径,加上后,所有路径都不显示,但是这行还能显出来,要让这行也消失地话就在它们前面 加一个即,另外命令地另一种用法,可以直接编辑文本文件,例如: >结晶果是在当前目录下生成一个地文件,双击直接执行这个文件时,就会执行这个命令资料个人收集整理,勿做商业用途 . . > 这个字符地意思是将">"前面地内容传递并且覆盖">"后面地内容,它所起地作用是将运行地回显结果传递到后面地范围. 例如:中地内容是,执行>即将地内容覆盖原有地.与这个资料个人收集整理,勿做商业用途 符号相似地还有>>它地功能不是覆盖而追加,即将运行后地内容加到原来地后. . 这是一个管道传输命令,意思是将上一命令执行地结果传到下一个命令去处理 例如: :\ "" 以上命令是:查找:\所有,并发现字符串.资料个人收集整理,勿做商业用途 :第一条命令第二条命令[ 第三条命令...] 用这种方法可以同时执行多条命令,当碰到执行正确地命令后将不执行后面地命令,如果没有出现正确地命令则一直执行完所有命令资料个人收集整理,勿做商业用途 ;(只要正确后面地就不执行) . ^ 是对特殊符号"<",">",""地前导字符,在命令中他将以上个符号地特殊功能去掉,仅仅只把他们当成符号而不使用他们地特殊资料个人收集整理,勿做商业用途 意义. 例如: :\> ^> 结果为:>没有追加只是显示出来而已 . 这个符号允许在一行中使用个以上不同地命令,当第一个命令执行失败了,也不影响后边地命令执行 例如::\> : : 结果是先后执行 . 这个命令和上边地类似,但区别是,第一个命令失败时,后边地命令也不会执行 例如::\> : : 由于电脑上没有盘所以显示结果为:系统找不到指定地路径.这样以来,后面地资料个人收集整理,勿做商业用途 两个盘就不执行啦.(当第个命令失败时此命令后面地命令将不再执行,也就是说一直执行到失败为止) . "" 双引号允许在字符串中包含空格,进入一个特殊目录可以用如下方法资料个人收集整理,勿做商业用途 " " * 以上三种方法都可以进入这个目录 . , 逗号相当于空格,在某些情况下“,”可以用来当做空格使 比如 :\ . ; 分号,当命令相同时,可以将不同目标用;来隔离,但执行效果不变,如执行过程中发生错误,则只返回错误报告,但程序还是资料个人收集整理,勿做商业用途 会执行. 比如: :\:\:\:\ 以上命令相当于 :\ :\ :\ :\ 但是前面执行地盘不存在地话,后面地命令将不会执行.资料个人收集整理,勿做商业用途 例如::\> : : 结果为:系统找不到指定地路径. .在地后面加一个点,所起到地作用是显示一空行.以下范例显示地批处理程序包含前后各有一个空行地三行消息: . .资料个人收集整理,勿做商业用途

Windows批处理大全

Windows 批处理大全(附各种实例) 批处理文件是无格式的文本文件,它包含一条或多条命令。它的文件扩展名为 .bat 或 .cmd。在命令提示下键入批处理文件的名称,或者双击该批处理文件,系统就会调用Cmd.exe按照该文件中各个命令出现的顺序来逐个运行它们。使用批处理文件(也被称为批处理程序或脚本),可以简化日常或重复性任务。当然我们的这个版本的主要内容是介绍批处理在入侵中一些实际运用,例如我们后面要提到的用批处理文件来给系统打补丁、批量植入后门程序等。下面就开始我们批处理学习之旅吧。 一.简单批处理内部命令简介 1.Echo 命令 打开回显或关闭请求回显功能,或显示消息。如果没有任何参数,echo 命令将显示当前回显设置。 语法 echo [{on|off}] [message] Sample:@echo off / echo hello world 在实际应用中我们会把这条命令和重定向符号(也称为管道符号,一般用> >> ^)结合来实现输入一些命令到特定格式的文件中.这将在以后的例子中体现出来。 2.@ 命令 表示不显示@后面的命令,在入侵过程中(例如使用批处理来格式化敌人的硬盘)自然不能让对方看到你使用的命令啦。 Sample:@echo off @echo Now initializing the program,please wait a minite... @format X: /q/u/autoset (format 这个命令是不可以使用/y这个参数的,可喜的是微软留了个autoset这个参数给我们,效果和/y是一样的。) 3.Goto 命令 指定跳转到标签,找到标签后,程序将处理从下一行开始的命令。 语法:goto label (label是参数,指定所要转向的批处理程序中的行。) Sample: if {%1}=={} goto nop arm s if {%2}=={} goto nop arm s(如果这里的if、%1、%2你不明白的话,先跳过去,后面会有详细的解释。) @Rem check parameters if null show usage :nop arm s echo Usage: monitor.bat ServerIP PortNumber goto end 标签的名字可以随便起,但是最好是有意义的字母啦,字母前加个:用来表示这个字母是标签,goto命令就是根据这个:来寻找下一步跳到到那里。最好有一些说明这样你别人看起来才会理解你的意图啊。 4.Rem 命令 注释命令,在C语言中相当与/*--------*/,它并不会被执行,只是起一个注释的

cmd中的特殊符号

cmd中的特殊符号 2007年05月31日星期四 00:46 @ \\隐藏命令的回显。 ~ \\在for中表示使用增强的变量扩展; 在set中表示使用扩展环境变量指定位置的字符串; 在set/a中表示按位取反。 % \\使用两个%包含一个字符串表示引用环境变量。比如一个%time%可以扩展到当前的系统时间; 单个%紧跟0-9的一个数字表示引用命令行参数; 用于for中表示引用循环变量; 连续的两个%表示执行时脱为一个%。 ^ \\取消转义字符,即将所有转义字符的转义作用关闭。比如要在屏幕显示一些特殊的字符,比如> >> | ^等时,就可以在其前面加一个^符号来显示这个^后面的字符了,^^就是显示一个^,^|就是显示一个|字符了; 在set/a中是按位异; 在findstr/r的[]中表示不匹配指定的字符集。 & \\命令连接字符。比如我要在一行文本上同时执行两个命令,就可以用&命令连接这两个命令; 在set/a中是按位与。 * \\代表任意个任意字符,就是我们通常所说的"通配符";比如想在c盘的根目录查找c盘根目录里所有的文本文件(.txt),那么就可以输入命令"dir c:\*.txt"; 在set/a中是乘法。比如"set/a x=4*2",得到的结果是8; 在findstr/r中表示将前一个字符多次匹配。 () \\命令包含或者是具有优先权的界定符吧,比如for命令要用到这个(),我们还可以在if,echo等命令中见到它的身影; - \\范围表示符,比如日期的查找,for命令里的tokens操作中就可以用到这个字符; 在findstr/r中连接两个字符表示匹配范围;

实用批处理(bat)教程

目录 第一章批处理基础 第一节常用批处理内部命令简介 1、REM 和:: 2、ECHO 和@ 3、PAUSE 4、ERRORLEVEL 5、TITLE 6、COLOR 7、mode 配置系统设备 8、GOTO 和: 9、FIND 10、START 11、assoc 和ftype 12、pushd 和popd 13、CALL 14、shift 15、IF 16、setlocal 与变量延迟(ENABLEDELAYEDEXPANSION / DISABLEDELAYEDEXPANSION 启动或停用延缓环境变量扩展名。) 17、ATTRIB显示或更改文件属性 第二节常用特殊符号 1、@命令行回显屏蔽符 2、%批处理变量引导符 3、> 重定向符 4、>>重定向符 5、<、>、<& 重定向符 6、|命令管道符 7、^转义字符 8、组合命令 9、& 组合命令 10、||组合命令 11、\"\"字符串界定符 12、, 逗号 13、; 分号 14、() 括号 15、! 感叹号 第二章FOR命令详解 一、基本格式 二、参数/d仅为目录 三、参数/R递归(文件名) 四、参数/L迭代数值范围 五、参数/F迭代及文件解析 第三章FOR命令中的变量

一、~I- 删除任何引号(\"),扩展%I 二、%~fI- 将%I 扩展到一个完全合格的路径名 三、%~dI- 仅将%I 扩展到一个驱动器号 四、%~pI- 仅将%I 扩展到一个路径 五、%~nI- 仅将%I 扩展到一个文件名 六、%~xI- 仅将%I 扩展到一个文件扩展名 七、%~sI- 扩展的路径只含有短名 八、%~aI- 将%I 扩展到文件的文件属性 九、%~tI- 将%I 扩展到文件的日期/时间 十、%~zI- 将%I 扩展到文件的大小 十一、%~$PATH:I 第四章批处理中的变量 一、系统变量 二、自定义变量 第五章set命令详解 一、用set命令设置自定义变量 二、用set命令进行简单计算 三、用set命令进行字符串处理 1、字符串替换 2、字符串截取 第六章if命令讲解 第一种用法:IF [NOT] ERRORLEVEL number command 第二种用法:IF [NOT] string1==string2 command 第三种用法:IF [NOT] EXIST filename command 第四种用法:IF增强的用法 第七章DOS编程高级技巧 一、界面设计 二、if…else…条件语句 三、循环语句 四、子程序 五、用ftp命令实现自动下载 六、用7-ZIP实现命令行压缩和解压功能 七、调用VBScript程序 八、将批处理转化为可执行文件 九、时间延迟 1、利用ping命令延时 2、利用for命令延时 3、利用vbs延迟函数,精确度毫秒,误差1000毫秒内 4、仅用批处理命令实现任意时间延迟,精确度10毫秒,误差50毫秒内 十、模拟进度条 十一、特殊字符的输入及应用 十二、随机数(%random%)的应用技巧 十三、变量嵌套与命令嵌套 1、更正了所有的错别字,适当排版,增加条理性。

bat基本应用

.bat文件的基本应用 bat是dos下的批处理文件。 首先批处理文件是一个文本文件,这个文件的每一行都是一条DOS命令(大部分时候就好像我们 在DOS提示符下执行的命令行一样),你可以使用DOS下的Edit或者Windows的记事本(notepad)等任何文本文件编辑工具来创建和修改批处理文件。 ==== 注 =================== 批处理文件中完全可以使用非dos命令,甚至可以使用不具有可执行特性的普通数据性文件,这缘 于windows系统这个新型解释平台的涉入,使得批处理的应用越来越"边缘化"。所以我们讨论的批 处理应该限定在dos环境或者命令行环境中,否则很多观念和设定都需要做比较大的变动。 ======================== 其次,批处理文件是一种简单的程序,可以通过条件语句(if)和流程控制语句(goto)来控制命令运行 的流程,在批处理中也可以使用循环语句(for)来循环执行一条命令。当然,批处理文件的编程能力 与C语言等编程语句比起来是十分有限的,也是十分不规范的。批处理的程序语句就是一条条的DOS命令(包括内部命令和外部命令),而批处理的能力主要取决于你所使用的命令。 ==== 注 ================== 批处理文件(batch file)也可以称之为批处理程序(batch program),这一点与编译型语言有所不同, 就c语言来说,扩展名为c或者cpp的文件可以称之为c语言文件或者c语言源代码,但只有编译 连接后的exe文件才可以称之为c语言程序。因为批处理文件本身既具有文本的可读性,又具有程 序的可执行性,这些称谓的界限是比较模糊的。 =========================== 第三,每个编写好的批处理文件都相当于一个DOS的外部命令,你可以把它所在的目录放到你的DOS搜索路径(path)中来使得它可以在任意位置运行。一个良好的习惯是在硬盘上建立一个bat或 者batch目录(例如C:\BATCH),然后将所有你编写的批处理文件放到该目录中,这样只要在path中设置上c:\batch,你就可以在任意位置运行所有你编写的批处理程序。 ==== 注 ===== 纯以dos系统而言,可执行程序大约可以细分为五类,依照执行优先级由高到低排列分别是:DOSKEY宏命令(预先驻留内存),https://www.doczj.com/doc/71532893.html,中的内部命令(根据内存的环境随时进驻 内存),以com为扩展名的可执行程序(由https://www.doczj.com/doc/71532893.html, 直接载入内存),以exe位扩展名的 可执行程序(由https://www.doczj.com/doc/71532893.html, 重定位后载入内存),以bat位扩展名的批处理程序(由https://www.doczj.com/doc/71532893.html, 解释分析,根据其内容按优先级顺序调用第2,3,4,5种可执行程序,分析一行,执行一行,文件本身不载入内存) ============ 第四,在DOS和Win9x/Me系统下,C:盘根目录下的AUTOEXEC.BAT批处理文件是自动运行批 处理文件,每次系统启动时会自动运行该文件,你可以将系统每次启动时都要运行的命令放入该文

批处理各符号的功能1.(新)

批处理各符号的功能1. echo有两个状态一个是on 一个是off默认的是on 它的功能是显示当前文件的路径,如果不写on 或者是off的时候,默认情况下 是打开的即显当前文件的路径,加上off后,所有路径都不显示,但是echo off这行还能显出来,要让这行也消失的话就在它们前面 加一个@即@echo off,另外echo命令的另一种用法,可以直接编辑文本文件,例如: echo netstat -an >a.bat结晶果是在当前目录下生成一个a.bat的文件,双击直接执行这个文件时,就会执行netstat -an这个命令 。 2. > 这个字符的意思是将">"前面的内容传递并且覆盖">"后面的内容,它所起的作用是将运行的回显结果传递到后面的范围. 例如:ipconfig.txt中的内容是1113333,执行ipconfig /all >ipconfig.txt即将ipconfig /all的内容覆盖原有的1113333。与这个 符号相似的还有>>它的功能不是覆盖而追加,即将运行后的内容加到原来的1113333后。 3. | 这是一个管道传输命令,意思是将上一命令执行的结果传到下一个命令去处理 例如: dir c:\|find "txt" 以上命令是:查找C:\所有,并发现TXT字符串。 || Usage:第一条命令|| 第二条命令[|| 第三条命令...] 用这种方法可以同时执行多条命令,当碰到执行正确的命令后将不执行后面的命令,如果没有出现正确的命令则一直执行完所有命令 ;(只要正确后面的就不执行) 4. ^ 是对特殊符号"<",">","&"的前导字符,在命令中他将以上3个符号的特殊功能去掉,仅仅只把他们当成符号而不使用他们的特殊 意义。 例如: C:\>echo ipconfig.txt ^>ipconfig

批处理文件修改注册表中的一些东西

这要修改注册表中的一些东西,给你一个批处理文件,设置一下就好了! 把以下部分复制粘贴到记事本中,保存,然后把保存的文件的扩展名.txt改成.bat然后双击执行! ================================================================= @ cls @ echo off @ title 刚子收集制作整理 ::2为绿色背景F为亮白色背景 @ color 2F @ ECHO. @ ECHO. @ ECHO ┏━━━━━━━━━━━━━━━━━━━━━━━━━┓ @ ECHO ┃┃ @ ECHO ┃刚子收集制作整理┃ @ ECHO ┃大家可以免费使用和修改┃ @ ECHO ┃┃ @ ECHO ┃QQ:15128965 ┃ @ ECHO ┃欢迎光临刚子博客:┃ @ ECHO ┃┃ @ ECHO ┗━━━━━━━━━━━━━━━━━━━━━━━━━┛ @ ECHO. @ ECHO. @ echo %date% %time% %ver% @ ECHO. ::将每行中的第二个和第三个符号传递给for 程序体;用逗号和/或空格定界符号。 ::请注意,这个for 程序体的语句引用%i 来取得第二个符号,引用%j 来取得第三个符号,引用%k来取得第三个符号后的所有剩余符号。 @ for /f "tokens=1,3*" %%i in ('ver') do set v=%%i %%j %%k @ echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @ echo. @ echo 计算机名:%COMPUTERNAME% @ echo 操作系统:%OS% @ echo 操作系统版本:%v% @ echo 系统所在分区:%systemdrive% @ echo 系统所在目录windows:%SystemRoot% @ echo 当前用户名:%USERNAME% @ echo 用户配置文件目录:%USERPROFILE% @ echo. @ echo ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ @ ECHO. ::%windir% 和%SystemRoot% 是一样的 ::for /r "%userprofile%\My Documents\" %%i in (*.*) do echo %%i >>1.txt

目前为止最全的批处理教程

目录 第一章 批处理基础 第一节 常用批处理内部命令简介 1、REM 和 :: 2、ECHO 和 @ 3、PAUSE 4、ERRORLEVEL 5、TITLE 6、COLOR 7、mode 配置系统设备 8、GOTO 和 : 9、FIND 10、START 11、assoc 和 ftype 12、pushd 和 popd 13、CALL 14、shift 15、IF 16、setlocal 与 变量延迟(ENABLEDELAYEDEXPANSION / DISABLEDELAYEDEXPANSION 启动或停用延缓环境变量扩展名。) 17、ATTRIB显示或更改文件属性 第二节 常用特殊符号

1、@命令行回显屏蔽符 2、%批处理变量引导符 3、> 重定向符 4、>>重定向符 5、<、>、<& 重定向符 6、|命令管道符 7、^转义字符 8、组合命令 9、& 组合命令 10、||组合命令 11、\"\"字符串界定符 12、, 逗号 13、; 分号 14、() 括号 15、! 感叹号 第二章 FOR命令详解 一、基本格式 二、参数 /d仅为目录 三、参数 /R递归(文件名) 四、参数 /L迭代数值范围 五、参数 /F迭代及文件解析 第三章 FOR命令中的变量

一、 ~I- 删除任何引号(\"),扩展 %I 二、 %~fI- 将 %I 扩展到一个完全合格的路径名 三、 %~dI- 仅将 %I 扩展到一个驱动器号 四、 %~pI- 仅将 %I 扩展到一个路径 五、 %~nI- 仅将 %I 扩展到一个文件名 六、 %~xI- 仅将 %I 扩展到一个文件扩展名 七、 %~sI- 扩展的路径只含有短名 八、 %~aI- 将 %I 扩展到文件的文件属性 九、 %~tI- 将 %I 扩展到文件的日期/时间 十、 %~zI- 将 %I 扩展到文件的大小 十一、 %~$PATH:I 第四章 批处理中的变量 一、系统变量 二、自定义变量 第五章 set命令详解 一、用set命令设置自定义变量 二、用set命令进行简单计算 三、用set命令进行字符串处理 1、字符串替换 2、字符串截取 第六章 if命令讲解 第一种用法:IF [NOT] ERRORLEVEL number command

批处理从入门到精通

批处理文件是将一系列命令按一定的顺序集合为一个可执行的文本文件,其扩展名为BAT。这些命令统称批处理命令,下面我就来给大家介绍一下批处理的命令。 1、REM REM 是个注释命令一般是用来给程序加上注解的,该命令后的内容在程序执行的时候将不会被显示和执行。例: REM 你现在看到的就是注解,这一句将不会被执行。在以后的例子中解释的内容都REM 会放在REM后面。请大家注意。 2、ECHO ECHO 是一个回显命令主要参数有OFF和ON,一般用ECHO message来显示一个特定的消息。例: Echo off Rem 以上代表关闭回显即不显示所执行的命令 Echo 这个就是消息。 Rem 以上代表显示“这就是消息”这列字符 执行结果: C:\>ECHO.BAT 这个就是消息。 3、GOTO GOTO 即为跳转的意思。在批处理中允许以“:XXX”来构建一个标号然后用GOTO :标号直接来执行标号后的命令。例 :LABEL REM 上面就是名为LABEL的标号。 DIR C:\ DIR D:\

GOTO LABEL REM 以上程序跳转标号LABEL处继续执行。 4、CALL CALL 命令可以在批处理执行过程中调用另一个批处理,当另一个批处理执行完后再继续执行原来的批处理。例: 批处理2.BAT内容如下: ECHO 这就是2的内容 批处理1.BAT内容如下: ECHO 这是1的内容 CALL 2.BAT ECHO 1和2的内容全部显示完成 执行结果如下: C:\>1.BAT 这是1的内容 这就是2的内容 1和2的内容全部显示完成 5、PAUSE PAUSE 停止系统命令的执行并显示下面的内容。例: C:\> PAUSE 请按任意键继续 . . . 6、IF IF 条件判断语句,语法格式如下: IF [NOT] ERRORLEVEL number command IF [NOT] string1==string2 command IF [NOT] EXIST filename command

dos批处理命令小程序

一.简单批处理内部命令简介 先来看一个垃圾清理批处理文件吧 @echo off echo 正在清除系统垃圾文件,请稍等...... del /f /s /q %systemdrive%\*.tmp del /f /s /q %systemdrive%\*._mp del /f /s /q %systemdrive%\*.log del /f /s /q %systemdrive%\*.gid del /f /s /q %systemdrive%\*.chk del /f /s /q %systemdrive%\*.old del /f /s /q %systemdrive%\recycled\*.* del /f /s /q %windir%\*.bak del /f /s /q %windir%\prefetch\*.* rd /s /q %windir%\temp & md %windir%\temp del /f /q %userprofile%\recent\*.* del /f /s /q "%userprofile%\Local Settings\Temporary Internet Files\*.*"

del /f /s /q "%userprofile%\Local Settings\Temp\*.*" del /f /s /q "%userprofile%\recent\*.*" echo 清除系统垃圾完成~ echo. & pause 将上面的内容保存为*.bat就可以运行了,清理系统垃圾 下面是详细讲解 1.Echo 命令 打开回显或关闭请求回显功能,或显示消息。如果没有任何参数,echo 命令将显示当 前回显设置。 语法 echo [{on|off}] [message] Sample:@echo off / echo hello world 在实际应用中我们会把这条命令和重定向符号(也称为管道符号,一般用> >> ^)

简单快速重命名同类文件(批处理基础)

有图有真相(完整图解) ●在所要重命名的文件夹中建立一个文本文档 ●输入“dir/a/b>1.txt”(引号不用,可直接复制) →保存→将文本文件的后缀名改为bat:即将文本文件命中的txt替换为bat,注意不能将“.”删掉, 然后会出现,就成功了。 ●双击上述文件,会在文件夹中出现1.txt,打开后将文件夹中文件的名字选中复制 ●新建Excel文件,将复制的文件名粘贴到A列 ●在B列写入重命名后的文件名,如下图

●在C列输入【"ren "&A1&" "&B1&RIGHTB(A1,4)】(可直接复制,注意:4代表所要命名文件的后缀名位数加上1;ren的后面和中间的双引号里有空格;由于文字格式的不同而导致复制粘贴不成功,则按上述括弧中在Excel 的C1输入如图 ●将鼠标移动到C1列的右下角,鼠标指针变为十字 形,如图按住鼠标不动往下拉,就可以完成所有的命令,如图

●将1.txt清空(Crtl+A→Backspace),在复制C列到1.txt,保存文本。 ●重命名1.txt,将后缀名改为bat,如第二个步骤 ●双击,你将会看到 ----→

为什么001没有改变呢? 虽然是批量重命名,但是B列中的名字必须符合文件的命名规则: 1.文件名长度规定 任何一个文件名最多可使用255个英文字符,如果使用中文字符则不能超过127个汉字。 2.可用字符规定 原则上可以利用键盘输入的英文字母、符号、空格、中文等均可以作为合法字符,但由于以下字符由系统保留它用,因此不能用在文件命名中: : / \ ? * “ < > | 3.经过实验,批处理重命名中B列不能出现 空格,否则将不能重命名。

批处理常用命令及用法大全_-__打印

注:如果对某一命令还不是很熟悉,可以在命令行窗口下输入:命令名/?的方式来获得帮助。 1 echo 和 @回显控制命令 @ #关闭单行回显 echo off #从下一行开始关闭回显 @echo off #从本行开始关闭回显。一般批处理第一行都是这个 echo on #从下一行开始打开回显 echo #显示当前是 echo off 状态还是 echo on 状态echo. #输出一个"回车换行",一般就是指空白行 echo hello world #输出hello world "关闭回显"是指运行批处理文件时,不显示文件里的每条命令,只显示运行结果批处理开始和结束时,系统都会自动打开回显 2 errorlevel程序返回码 echo %errorlevel%每个命令运行结束,可以用这个命令行格式查看返回码用于判断刚才的命令是否执行成功默认值为0,一般命令执行出错会设 errorlevel 为1 3 dir显示目录中的文件和子目录列表 dir #显示当前目录中的文件和子目录 dir /a #显示当前目录中的文件和子目录,包括隐藏文件和系统文件 dir c: /a:d #显示 C 盘当前目录中的目录 dir c:\ /a:-d #显示 C 盘根目录中的文件 dir d:\mp3 /b/p #逐屏显示 d:\mp3 目录里的文件,只显示文件名,不显示时间和大小 dir *.exe /s显示当前目录和子目录里所有的.exe文件其中 * 是通配符,代表所有的文件名,还一个通配符 ? 代表一个任意字母或汉字如 c*.* 代表以 c 开头的所有文件?.exe 代表所有文件名是一个字母的.exe文件如果指定的目录或文件不存在,将返回 errorlevel 为1;每个文件夹的 dir 输出都会有2个子目录 . 和 ... 代表当前目录.. 代表当前目录的上级目录 dir . #显示当前目录中的文件和子目录 dir .. #显示当前目录的上级目录中的文件和子目录 其它参数可参考 dir /? 4 cd更改当前目录 cd mp3 #进入当前目录中的mp3 目录 cd .. #进入当前目录中的上级目录 cd\ #进入根目录 cd #显示当前目录 cd /d d:\mp3 #可以同时更改盘符和目录 cd "Documents and Settings"\All users文件名带空格,路径前需要加上引号!!如果更改到的目录不存在,则出错返回 errorlevel=1 5 md创建目录 md abc #在当前目录里建立子目录 abc md d:\a\b\c #如果 d:\a 不存在,将会自动创建 6 rd删除目录 rd abc #删除当前目录里的 abc 子目录,要求为空目录 rd /s/q d:\temp #删除 d:\temp 文件夹及其子文件夹和文件,不需要按 Y 确认 7 del删除文件 del d:\test.txt #删除指定文件,不能是隐藏、系统、只读文件 del *.*删除当前目录里的所有文件,不包括隐藏、系统、只读文件,要求按 Y 确认 del /q/a/f d:\temp\*.*删除 d:\temp 文件夹里面的所有文件,包括隐藏、只读、系统文件,不包括子目录 del /q/a/f/s d:\temp\*.*删除 d:\temp 及子文件夹里面的所有文件,包括隐藏、只读、系统文件,不包括子目录 8 ren文件重命名 ren 1.txt 2.bak #把 1.txt 更名为 2.bak ren *.txt *.ini #把当前目录里所有.txt文件改成.ini文件 ren d:\temp tmp #支持对文件夹的重命名 9 cls清屏 10 type显示文件内容 type c:\boot.ini #显示指定文件的内容,程序文件一般会显示乱码 type *.txt #显示当前目录里所有.txt文件的内容 11 copy拷贝文件 XCOPY复制组文件 COPY复制文件 拷贝目录和文件——xcopy 在拷贝单个文件时,可以使用copy命令完成,但当我们要成批拷贝文件,甚至连同子目录一起拷贝时,就要用到xcopy。 copy c:\test.txt d:\复制 c:\test.txt 文件到 d:\ copy c:\test.txt d:\test.bak复制 c:\test.txt 文件到 d:\ ,并重命名为 test.bak copy c:\*.*复制 c:\ 所有文件到当前目录,不包括隐藏文件和系统文件不指定目标路径,则默认目标路径为当前目录 copy con test.txt从屏幕上等待输入,按 Ctrl+Z 结束输入,输入内容存为test.txt文件con代表屏幕,prn 代表打印机,nul代表空设备 copy 1.txt + 2.txt 3.txt合并 1.txt 和 2.txt 的内容,保存为 3.txt 文件如果不指定 3.txt ,则保存到 1.txt 1

批处理常用符号详解

(一)@ 一般在它之后紧跟一条命令或一条语句,则此命令或语句本身在执行的时候不会显示在屏幕上。请把下面的代码保存为test.cmd文件,然后运行,比较一下两条echo语句在屏幕上的输出差异: echo a @pause @echo b @pause 执行结果如下: C:\Documents and Settings\JM\桌面>echo a a 请按任意键继续... 请按任意键继续... (二)%、%% 百分号用在不同的场合,有不同的含义: 1)当百分号成对出现,并且其间包含非特殊字符时,一般做变量引用处理,比如:%var%、%str%。把以下代码 保存为批处理文件,运行后观察屏幕显示结果: @echo off setstr=abc echo 变量str的值是:%str% pause 在屏幕上将显示这样的结果: 变量str的值是:abc 按任意键继续... 另外,百分号作为变量引用还有一种特殊形式,那就是对形式参数的引用,此时,单个百分号后面紧 跟0~9这10个数字,如%0、%1,其中,%0为脚本本身的名称,%1至%9为第二至九个参数...最多支 持%0~%9,%10以后就是变量引用了,即%15为%1的值接上5。 请看演示代码: @echo off if defined strgoto next setstr= set /p str=请把文件拉到本窗口后回车: call "%~0" %str% pause exit :next cls echo 本批处理文件完整路径为:"%~0" echo 拖到本窗口的文件完整路径为:"%~1" goto :eof

对形式参数的引用 1、获取批处理自身的完整路径 echo %0 pause 2、获取批处理自身的完整路径,并去掉首尾的引号 echo %~0 pause 3、获取批处理自身的文件名及后缀名 echo %~nx0 pause 4、获取批处理自身的文件名 echo %~n0 pause 5、获取批处理自身的后缀名 echo %~x0 pause 6、获取批处理自身的完整路径,不含文件名 echo %~dp0 pause 或 echo %cd% pause 7、获取批处理自身的盘符 echo %~d0 pause 8、获取批处理自身的大小 echo %~z0 pause 9、获取批处理自身的修改时间 echo %~t0 pause 2)出现在set /a 语句中时,表示两数相除取余数,也就是所谓的模运算,它在命令行窗口和批处理文件中的写 法略有差异:在命令行窗口中,只需要单个的%,在批处理文件中,需要连续两个百分号,写成%%。 例如:在命令行窗口中,运行set /a num=4%2 ,则结果将显示0,因为4除以2的余数为0;如果保存为批处理文件,则此语句将略有改变: @echo off set /a num=4%%2 echo 4除以2的余数为%num% pause 3)转义符号:如果要显示%本身时,需要在前面用%来转义。例如: @echo off echo 一个百分号:%% echo 两个百分号:%%%% echo 三个百分号:%%%%%% pause

DOS下符号的作用参考

正文开始: ____________________________________________________________________________________ ______ 一、单符号 ~ ①在for中表示使用增强的变量扩展。 ②在%var:~n,m%中表示使用扩展环境变量指定位置的字符串。 ③在set/a中表示一元运算符,将操作数按位取反。 ! ①在set /a中一元运算符,表示逻辑非。比如set /a a=!0,这时a就表示逻辑1。 @ ①隐藏命令行本身的回显,常用于批处理中。 $ ①在findstr命令里面表示一行的结束。 ②在prompt命令里面,表示将其后的字符转义(符号化或者效果化)。 % ①在set /a中的二元运算符,表示算术取余。 ②命令行环境下,在for命令in前,后面接一个字符(可以是字母、数字或者一些特定字符),表示指定一个循环或者遍历指标变量。 ③批处理中,后接一个数字表示引用本批处理当前执行时的指定的参数。 ④其它情况下,%将会被脱去(批处理)或保留(命令行) ^ ①取消特定字符的转义作用,比如& | > < ! "等,但不包括%。比如要在屏幕显示一些特殊的字符,比如> >> | ^ &等符号时,就可以在其前面加一个^符号来显示这个^后面的字符了,^^就是显示一个^,^|就是显示一个|字符了; ②在set/a中的二元运算符,表示按位异或。 ③在findstr/r的[]中表示不匹配指定的字符集。 & ①命令连接字符。比如我要在一行文本上同时执行两个命令,就可以用&命令连接这两个命令。 ②在set/a中是按位与。 * ①代表任意个任意字符,就是我们通常所说的"通配符";比如想在c盘的根目录查找c盘根目录里所有的文本文件(.txt),那么就可以输入命令"dir c:\*.txt"。 ②在set /a中的二元运算符,表示算术乘法。 ③在findstr/r中表示将前一个字符多次匹配。 -

批处理中符号作用大全

批处理中符号作用大全 @ //隐藏命令的回显。 ~ //在for中表示使用增强的变量扩展; 在set中表示使用扩展环境变量指定位置的字符串; 在set/a中表示按位取反。 % //使用两个%包含一个字符串表示引用环境变量。比如一个%time%可以扩展到当前的系统时间; 单个%紧跟0-9的一个数字表示引用命令行参数; 用于for中表示引用循环变量; 连续的两个%表示执行时脱为一个%。

^ //取消转义字符,即将所有转义字符的转义作用关闭。比如要在屏幕显示一些特殊的字符,比如> >> | ^等时,就可以在其前面加一个^符号来显示这个^后面的字符了,^^就是显示一个^,^|就是显示一个|字符了; 在set/a中是按位异; 在findstr/r的[]中表示不匹配指定的字符集。 & //命令连接字符。比如我要在一行文本上同时执行两个命令,就可以用&命令连接这两个命令; 在set/a中是按位与。 * //代表任意个任意字符,就是我们通常所说的"通配符";比如想在c盘的根目录查找c盘根目录里所有的文本文件(.txt),那么就可以输入命令"dir c:/*.txt";

在set/a中是乘法。比如"set/a x=4*2",得到的结果是8; 在findstr/r中表示将前一个字符多次匹配。 () //命令包含或者是具有优先权的界定符吧,比如for命令要用到这个(),我们还可以在if,echo等命令中见到它的身影; - //范围表示符,比如日期的查找,for命令里的tokens操作中就可以用到这个字符; 在findstr/r中连接两个字符表示匹配范围; -跟在某些命令的/后表示取反向的开关。 + //主要是在copy命令里面会用到它,表示将很多个文件合并为一个文件,就要用到这个+字符了; 在set/a中是加法。 |

bat 语法点滴 批处理 Set 命令详解 让你理解set命令

bat 语法点滴批处理 Set 命令详解让你理解set命令 2011年05月06日星期五 15:30 1.转义符 ^ ^" = " 2. 另外,FOR 中的变量已被增强,我们可以使用下列句法来引用变量: %~I - 扩充 %I 为删除外围 " 引号(有就删) %~fI - 扩充 %I 为一个完整的路径 %~dI - 仅扩充 %I 为一个驱动器号 %~pI - 仅扩充 %I 为一个路径 %~nI - 仅扩充 %I 为一个文件名 %~xI - 仅扩充 %I 为一个文件扩展名 %~sI - 扩充 %I 为完整的短名路径 %~aI - 扩充 %I 为文件的属性(ARSH) %~tI - 扩充 %I 为文件的日期时间(修改时间) %~zI - 扩充 %I 为文件的大小(字节计) %~$PATH:I - ◎变量可以是其他的,如:WinDIR、ProgramFiles 等 在环境变量 PATH 指定的路径中搜索文件, 扩充 %I 为找到的第一个文件的完整路径; 若未找到文件,则扩充 %I 为空。 组合扩展参数效果: %~dpI - 仅扩充 %I 为驱动器号和路径 %~nxI - 仅扩充 %I 为文件名加扩展名 %~fsI - 扩充 %I 为完整的短名路径(同 %~sI) %~dp$PATH:I - 搜索变量 PATH 中的路径, 仅扩充 %I 为找到的第一个文件驱动器号和路径。%~ftzaI - 扩充 %I 为类似 DIR 命令的输出格式 以上例子中,%I 和 PATH 可用其他有效的变量替代。 %~ 百分号加波浪线用法是后面必须跟有效的 FOR 变量名。 推荐使用诸如 %I 的大写变量名,这样不仅易读且可避免混淆。 ◎当然这是因人而异的。 如果是for中的变量例如%%i 可以写成%%~ni

相关主题
文本预览
相关文档 最新文档