zoukankan      html  css  js  c++  java
  • 批处理基础

    基本语法
    删除目录下所有文件

    @ECHO OFF 
    DEL . 
    DR

    列出文件列表输入到文件

    @echo off
    dir "C:Program Files" >b.txt
    pause

    设置变量SET

    @echo off 
    set message=Hello World 
    echo %message%
    pause

    局部变量&全局变量,SETLOCAL 和ENDLOCAL之间包裹着局部变量

    @echo off 
    set globalvar=5
    SETLOCAL               
    set var=13145
    set /A var=%var% + 5      /A 用在声明数字时
    echo %var%
    echo %globalvar%
    ENDLOCAL

    系统环境变量

    @echo off 
    echo %JAVA_HOME%

    字符串

    set message=Hello World  创建字符串
    Set a=                             创建空字符串
    
    检验字符串是否为空
    @echo off 
    SET a= 
    SET b=Hello 
    if [%a%]==[] echo "String A is empty" 
    if [%b%]==[] echo "String B is empty "
    
    字符串拼接
    @echo off 
    SET a=Hello 
    SET b=World 
    SET /A d=50 
    SET c=%a% and %b% %d%
    echo %c%
    转变为数字类型
    @echo off
    set var=13145
    set /A var=%var% + 5
    echo %var%
    取前五个字符
    @echo off 
    set str=Helloworld        
    echo %str%                   Helloworld     
    set str=%str:~0,5%       Hello
    echo %str%
    
    字符串替换
    @echo off 
    set str=Batch scripts is easy. It is really easy. 
    echo %str% 
    set str=%str:is=% 
    echo %str%
    去掉空格
    @echo off 
    set str=This string    has    a  lot  of spaces 
    echo %str% 
    
    set str=%str:=%      
    echo %str%                   Thisstringhasalotofspaces
  • 相关阅读:
    BETA 版冲刺前准备
    Alpha 事后诸葛亮(团队)
    Learn Docker(一)—软件安装与常规操作
    Alpha 答辩总结
    Alpha 冲刺 (10/10)
    Alpha 冲刺 (9/10)
    Alpha 冲刺 (8/10)
    Alpha 冲刺 (7/10)
    Alpha 冲刺 (6/10)
    团队作业-随堂小测(同学录)
  • 原文地址:https://www.cnblogs.com/webdev8888/p/9103930.html
Copyright © 2011-2022 走看看