程序在执行时关闭(批处理)

时间:2015-02-02 09:14:44

标签: windows batch-file if-statement cmd

所以这应该检查这些文件是否存在于%HOMEPATH%中,但它只能在10:05和13:15之间执行

@echo off & cls
color 8f
set HORA = %time:~0,2%%time:~3,2%
if %HORA% GEQ 1005 (
    if %HORA% LEQ 1315 (
        cd %HOMEPATH%
        if EXIST Desktop (
            echo Desktop hi es >> registre.log
            ) ELSE ( echo Desktop no hi es >> registre.log
            )
        if EXIST Music (
            echo Music hi es > registre.log
            ) ELSE ( echo Music no hi es > registre.log
            )
        if EXIST Documents (
            echo Mis Documentos hi es > registre.log
            ) ELSE ( Mis Documentos no hi es > registre.log
            )
        if EXIST Downloads (
            echo Descarregues hi es > registre.log
            ) ELSE ( Descarregues no hi es > registre.log
            )
        type registre.log
        pause > nul
        del registre.log
    )
)
echo Ara no es pot executar
pause
exit

当我打开文件时,它会立即关闭

1 个答案:

答案 0 :(得分:3)

          v.......................... space included in variable value 
set HORA = %time:~0,2%%time:~3,2%
        ^...........................  space included in variable name

因此,要引用您的变量,您需要%HORA %。更好地改变

set "HORA=%time:~0,2%%time:~3,2%"

没有空格和引号(未包含在值中)也会阻止在行尾添加aditional空格。