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
  • 相关阅读:
    UVA 1001 Say Cheese
    UVa 821 Page Hopping
    UVA 1569 Multiple
    UVA 1395 Slim Span
    UVA 12219 Common Subexpression Elimination
    UVA 246 10-20-30
    Mysql基本操作
    浅析关键字static
    面试回答技巧
    五个程序员好习惯
  • 原文地址:https://www.cnblogs.com/webdev8888/p/9103930.html
Copyright © 2011-2022 走看看