---
title: "DOS set command"
author: "klts"
date: "2012-12-11T13:45:49Z"
tags: []
categories: ["编程语言"]
slug: "dos-set-command"
draft: false
lastmod: "2012-12-11T13:45:49Z"
id: 1745802
url: "https://klts.iteye.com/blog/1745802"
---

if \[not] '%参数%'=='值' 待执行命令

if exist D:\\a.txt type D:\\a.txt                判断是否存在a.txt文件，并输出文件里的信息

xcopy D:\\a.txt D:\\a2.txt                       复制a.txt文件到a2.txt文件

for %%c in (\*.bat,\*.txt) do echo %%c       遍历当前目录下所有bat和txt文件，并输出文件名（如果echo变为type,则输出文件里的信息）

if errorlevel 0 echo success                  通过errorlevel的值判断执行成功与否

 

 

 

bat文件简单例子

 

@ECHO off  
cls  
:start  
ECHO.  
set var=before  
if not '%var%'=='before' goto start  
set var=after  
if '%var%'=='after' goto result

goto start  
:result  
ECHO if you look this, i done.  
goto end  
:end  
pause