批处理文件重复先前的工作程序 [英] batch file repeating previous working program

查看:62
本文介绍了批处理文件重复先前的工作程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请在我的批处理脚本方面需要帮助.它运行得很好,但是后来我想运行它时,请重复显示它的先前结果.例如,我上周执行了一个名为echo运行的程序该程序在上周的第一周运行",而当我试图通过echo今天运行的今天"This is Today".它运行并显示先前的结果"

Please I need help regarding my batch script. It was running perfectly, but later on when I wanted to run it keep repeating my previous result it displayed. eg I executed a program last week called to run echo " The program run at first last week", and by the time I tried to run it today by echo " This is today". It ran and displayed the previous result "

PS该代码现在可以正常工作了.... @回声关闭

PS The code is working perfectly now.... @echo off

SETLOCAL ENABLEDELAYEDEXPANSION
set file="C:\compress.gdb"


if not exist %file% goto :EOF
FOR %%A IN (%file%) DO set size=%%~zA

>"%temp%\math.vbs" echo Set objArgs = WScript.Arguments: num = objArgs(0) : result = 0
>>"%temp%\math.vbs" echo if num ^> 1073741824 then result=1
>>"%temp%\math.vbs" echo if num ^> 6442450944 then result=2
>>"%temp%\math.vbs" echo Wscript.echo result

for /f %%a in ('cscript /nologo "%temp%\math.vbs" %size% ') do set z=%%a

del "%temp%\math.vbs"

:: z will be 2 if %size% greater than 6442450944
:: z will be 1 if %size% greater than 1073741824
:: z will be 0 if %size% less    than 1073741825

echo %z%

if %z% EQU 2 (goto EXECUTE)
if %z% EQU 0 (goto LOGOUT)
if %z% EQU 1 (goto LOGOUT)

goto :EOF

:EXECUTE

call "C:\Batch_Scripts_Sensitive\message.rtf" /max
"C:\Program Files\Embarcadero\InterBase\bin\isql" -i "C:\Batch_Scripts_Sensitive\Empty_Tables_2.sql" localhost:"C:\Program Files (x86)\GE Aviation\AB139 HGS\DB\compress.GDB" -user xxxxxxx -pass xxxxxxx

:: Create Date for Back up and Restore

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-4%
echo year=%year%
set month=%date:~3,2%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~0,2%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

rem use this if you want to add seconds rem set datetimef=mydate_%year%_%month%_%day%_%hour%:%min%:%secs%
set datetimef=%year%_%month%_%day%_%hour%%min%
echo datetimef=%datetimef%
mkdir "C:\Monthly-gdb-restore\%datetimef%"


copy "C:\compress.gdb" "C:\Monthly-gdb-restore\%datetimef%" /Y


:: Delete empty folder in this location %Datetime%

for /f "delims=" %%d in ('dir "C:\Monthly-gdb-restore" /s /b /ad ^| sort /r') do rd "%%d"


forfiles /P "C:\Monthly-gdb-restore"  /S /M *.gdb /D -7 /C "cmd /c del @PATH /q"

"C:\Program Files\Embarcadero\InterBase\bin\gbak"   -b "C:\compress.gdb" "C:\compress.ibk"  -user xxxxxxx -password xxxxxxx

set hour=%time:~0,2%
if "%hour:~0,1%" == " " set hour=0%hour:~1,1%
echo hour=%hour%
set min=%time:~3,2%
if "%min:~0,1%" == " " set min=0%min:~1,1%
echo min=%min%
set secs=%time:~6,2%
if "%secs:~0,1%" == " " set secs=0%secs:~1,1%
echo secs=%secs%

set year=%date:~-4%
echo year=%year%
set month=%date:~3,2%
if "%month:~0,1%" == " " set month=0%month:~1,1%
echo month=%month%
set day=%date:~0,2%
if "%day:~0,1%" == " " set day=0%day:~1,1%
echo day=%day%

rem use this if you want to add seconds rem set datetimef=mydate_%year%_%month%_%day%_%hour%:%min%:%secs%
set datetimef=%year%_%month%_%day%_%hour%%min%
echo datetimef=%datetimef%
mkdir "C:\Monthly-ibk-backup\%datetimef%"

copy "C:\compress.ibk"   "C:\Monthly-ibk-backup\%datetimef%"  /Y

:: Delete empty folder in this location %Datetime%

for /f "delims=" %%d in ('dir "C:\Monthly-ibk-backup" /s /b /ad ^| sort /r') do rd "%%d"

forfiles /P "C:\Monthly-ibk-backup"  /S /M *.ibk /D -7 /C "cmd /c del @PATH /q"

"C:\Program Files\Embarcadero\InterBase\bin\gbak"  -R "C:\compress.ibk" "C:\compress.gdb" -user xxxxxxx -password xxxxxxx

 goto FINISH


:LOGOUT

Echo " The size of the database file is not up to 6GB

goto :EOF

:FINISH

ECHO " The database for xxxxxxx  was up to 6GB OR MORE, therefore proper backup and restoration has been performed.





goto :EOF

推荐答案

如果两次在同一控制台窗口中运行它,则问题可能是未初始化的变量,并且您看到的是最后结果.

If you are running it in the same console window both times then the problem will likely be an uninitialised variable, and you are seeing the last result.

要使用VBS检查数字,请尝试将其作为代码的第一部分. 留在最后一个goto :eof中,以阻止它通过比较落入以下代码.

To use VBS to check the numbers then try this as the first part of your code. Leave in the last goto :eof to stop it falling through the compare into the following code.

检查最终结果(如果比较),以确保他们正在执行您想要的操作.

Check the final if compares to be sure they are doing what you want.

@echo off
SETLOCAL ENABLEDELAYEDEXPANSION
set file="C:\Program Files (x86)\GE Aviation\AB139 HGS\DB\AW139 DB.gdb"


if not exist %file% goto :EOF
FOR %%A IN (%file%) DO set size=%%~zA

>"%temp%\math.vbs" echo Set objArgs = WScript.Arguments: num = objArgs(0) : result = 0
>>"%temp%\math.vbs" echo if num ^> 1073741824 then result=1
>>"%temp%\math.vbs" echo if num ^> 6442450944 then result=2
>>"%temp%\math.vbs" echo Wscript.echo result

for /f %%a in ('cscript /nologo "%temp%\math.vbs" %size% ') do set z=%%a

del "%temp%\math.vbs"

:: z will be 2 if %size% greater than 6442450944
:: z will be 1 if %size% greater than 1073741824
:: z will be 0 if %size% less    than 1073741825

if %z% EQU 2 (goto EXECUTE) 
if %z% EQU 1 (goto EXECUTE) 
if %z% EQU 0 (goto LOGOUT)

goto :EOF

这篇关于批处理文件重复先前的工作程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆