Last active
May 27, 2018 16:44
-
-
Save kazuya-k-ishibashi/684aa296b9ed134438f2f44884c185fe to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
setlocal enabledelayedexpansion | |
set BAT_DIR=%~dp0 | |
:: config | |
set r_flg=0 | |
:: execute | |
for %%i in (%*) do ( | |
if "!r_flg!" == "1" ( | |
set root="%%~i" | |
set r_flg=0 | |
) else if "%%~i" == "--root" ( | |
set r_flg=1 | |
) else if "%%~i" == "-r" ( | |
set r_flg=1 | |
) else if "!froms!" == "" ( | |
set froms="%%~i" | |
) else if "!to!" == "" ( | |
set to="%%~i" | |
) else ( | |
set froms=!froms! !to! | |
set to="%%~i" | |
) | |
) | |
if "%root%" == "" ( | |
rem 絶対パスにしたいところ | |
set root=. | |
) | |
:::: validation: fromsが空だったら、toが空だったら | |
rem echo root: %root% | |
rem echo froms: %froms% | |
rem echo to: %to% | |
for %%i in (%root%) do set root_fullpath=%%~dpnxi | |
for %%i in (%to%) do set to_fullpath=%%~dpnxi | |
for %%i in (%froms%) do call :cp %%i | |
:end | |
endlocal | |
exit /b | |
:cp | |
setlocal | |
set to_file_fullpath=%to_fullpath%\%~1 | |
for %%i in ("%to_file_fullpath%") do set to_dir_fullpath=%%~dpi | |
rem 拡張コマンドonでないといけない | |
mkdir %to_dir_fullpath% | |
for %%i in ("%root_fullpath%\%~1") do set from_file_fullpath=%%~dpnxi | |
copy "%from_file_fullpath%" "%to_file_fullpath%" | |
endlocal | |
exit /b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment