LoginSignup
0
0

More than 5 years have passed since last update.

cmd - 第1引数で指定したファイルを第2引数で指定したフォルダに移す

Last updated at Posted at 2015-10-31

@echo off
@rem 第1引数で指定したファイルを、第2引数で指定したフォルダに移す
if (%2)==() goto error
if exist %1 goto del_old
echo "ERROR: not found %1"
goto exit

:del_old
@rem 移動先に同名のファイルがあったら消す
if exist %2\%1 del %2\%1
@rem 移動先に同名のファイルが無ければ移動処理(move_to)へ進む
if not exist %2\%1 goto move_to
@echo "ERROR: could not delete old file"
goto exit

:move_to
@copy %1 %2\%1
if exist %2\%1 goto del_src
@echo "ERROR: could not copy"
goto exit

:del_src
del %1
if not exist %1 goto finish
@echo "ERROR: could not delete original file"
goto exit

:finish
@echo "%0 is finished."
goto exit

:error
@echo "Usage: %0 source dest"

:exit

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0