Yahoo! 지혜봉투(q11126934051)

「Yahoo! 지혜봉투」의 이하의 질문을 풀어 보았습니다.


q11126934051.bat
@echo off

set SELF=%~n0

setlocal
  set SOURCE=E:
  set TARGET=.\BACKUP

  echo WScript.Echo MsgBox^("Do you want to make backup copy of this file?" ^& vbCrLf ^& vbCrLf ^& WScript.Arguments^(0^), vbYesNo^) > .\%SELF%.vbs

  for %%i in (A B C) do (
    call :choice "%SOURCE%\%%i" && (
      call :backup "%SOURCE%\%%i" "%TARGET%\%%i" && (
        echo [  OK  ] %SOURCE%\%%i to %TARGET%\%%i\
      ) || (
        echo [  NG  ] %SOURCE%\%%i to %TARGET%\%%i\
      )
    ) || (
        echo [ SKIP ] %SOURCE%\%%i to %TARGET%\%%i\
    )
  )

  del .\%SELF%.vbs > NUL
endlocal
goto :EOF

:choice
setlocal
  for /f "tokens=*" %%i in ('cscript //nologo %SELF%.vbs "%~1"') do (set i=%%i)

  :: vbYes: 6, vbNo: 7
  if %i% equ 7 (exit /b 1)

  exit /b 0
endlocal
goto :EOF

:backup
setlocal enabledelayedexpansion
  set SOURCE=%~1
  set TARGET=%~2

  if "%SOURCE%" == "" (
    echo %SELF%: insufficient argument: #1 >&2
    exit /b 1
  )
  if "%TARGET%" == "" (
    echo %SELF%: insufficient argument: #2 >&2
    exit /b 1
  )

  if not exist "%SOURCE%" (
    echo %SELF%: file not found: %SOURCE% >&2
    exit /b 1
  )

  if not exist "%TARGET%\" (
    md "%TARGET%"
    if !ERRORLEVEL! neq 0 (
      echo %SELF%: failed to create directory: %TARGET% >&2
      exit /b 1
    )
  )

  copy "%SOURCE%" "%TARGET%" > NUL
  if %ERRORLEVEL% neq 0 (
    echo %SELF%: failed to copy file: %SOURCE% >&2
    exit /b 1
  )

  exit /b 0
endlocal
goto :EOF

실행하면
E:\>tree /f E:\
フォルダ パスの一覧:  ボリューム XXXXXXXX
ボリューム シリアル番号は XXXX-XXXX です
E:\
    A
    B


C:\temp>q11126934051.bat
[  OK  ] E:\A to .\BACKUP\A\
[ SKIP ] E:\B to .\BACKUP\B\
q11126934051: file not found: E:\C
[  NG  ] E:\C to .\BACKUP\C\


C:\temp>tree /f .\BACKUP
フォルダ パスの一覧:  ボリューム ローカル ディスク
ボリューム シリアル番号は XXXX-XXXX です
C:\temp\BACKUP
└─A
        A

파일을 복사하기 전에 다음과 같은 대화 상자가 나타납니다.

좋은 웹페이지 즐겨찾기