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

そして、エラーレベルを使用して、アクションが発生したときに各ファイルのステータスを確認したいと思います.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 に答える