因此,假设我在批处理文件中有以下代码:
Del Build6.log
Ren Build5.log Build6.log
Ren Build4.log Build5.log
Ren Build3.log Build4.log
Ren Build2.log Build3.log
Ren Build.log Build2.log
我想用Errorlevel来验证每个文件的状态,因为它们发生了一个动作,让我们说Build6.log不存在或者它正被另一个程序或函数使用。我怎么会最好的呢?
或者我应该刮掉整个用户和用户Powershell吗?
答案 0 :(得分:0)
@echo off
@break off
@title verify file errors on batch files
@color 0a
@cls
setlocal EnableDelayedExpansion
REM Delete Command
if not exist Build6.log (
echo File "Build6.log" don't exists
) else (
del Build6.log>nul 2>&1
if exist Build6.log (
echo Failure during file deletion
) else (
echo deleted file successfully
)
)
REM Rename Command
if not exist Build5.log (
echo File "Build5.log" don't exists
) else (
ren Build5.log Build6.log>nul 2>&1&if !ErrorLevel! EQU 1 ( echo Failure during file renaming, probably a file with the new name already exists in the directory ) else ( echo File successfully renamed )
)
pause
exit