0

因此,假设我在批处理文件中有以下代码:

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?

4

1 回答 1

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
于 2014-01-13T19:33:47.153 回答