Windows batch scripting notes








  • pass all arguments:
    java -jar app.jar %*
  • logical AND in IF conditionals
    IF %age% geq 18 (
        IF %age% leq 68 (
            SET class=working
        )
    )
    
    IF %age% geq 0 IF %age% leq 18 SET class=children
    
  • logical OR in IF conditionals
    SET children_or_elderly=F
    IF %age% leq 18 set children_or_elderly=T
    IF %age% geq 60 set children_or_elderly=T
    IF "%children_or_elderly%"=="T" (
        ECHO kids or retired
    )
    
  • Test if the argument exists
    IF [%1] == [] ECHO No arguments
  • Count number of arguments
    SET nbArgs=0
    FOR %%x IN (%*) DO SET /A nbArgs+=1
    ECHO %nbArgs%
    
  • Check if file exists
    IF EXIST C:\TEST\FILE1.TXT ECHO exists
    IF NOT EXIST C:\FILE2.TXT ECHO not exist
    






see also




No comments:

Post a Comment