Skip to content

Instantly share code, notes, and snippets.

@libraplanet
Last active April 29, 2016 15:42
Show Gist options
  • Save libraplanet/6275bd0af686f62a13aad9850cc1fe5a to your computer and use it in GitHub Desktop.
Save libraplanet/6275bd0af686f62a13aad9850cc1fe5a to your computer and use it in GitHub Desktop.
move files recursive to directory from directory, keeping sub directory tree.
@SETLOCAL
@GOTO :sub_main
@REM ----------------------------------------------------------------------------------------------
@REM -- sub_list
@REM -- arg[1] : dir path
@REM ----------------------------------------------------------------------------------------------
:sub_list
@SET BASE_DIR=%~1
@REM normalize source path.
@SET _SRC_DIR_PATH=%BASE_DIR%\
@SET _SRC_DIR_PATH=%BASE_DIR:\\=\%
@REM output list.
@DIR /S /B "%BASE_DIR%*.mp4" 2> NUL
@DIR /S /B "%BASE_DIR%*.mkv" 2> NUL
@DIR /S /B "%BASE_DIR%*.aac" 2> NUL
@DIR /S /B "%BASE_DIR%*.mp3" 2> NUL
@GOTO :EOF
@REM ----------------------------------------------------------------------------------------------
@REM -- sub_move
@REM -- arg[1] : src dir path
@REM -- arg[2] : src file path
@REM ----------------------------------------------------------------------------------------------
:sub_move
@REM @ECHO [sub_move]
@REM @ECHO arg1=%~1
@REM @ECHO arg2=%~2
@SET _CUR_DIR_PATH=%~dp0
@SET _SRC_DIR_PATH=%~1
@SET _SRC_FILR_PATH=%~2
@REM normalize source path.
@SET _SRC_DIR_PATH=%_SRC_DIR_PATH%\
@SET _SRC_DIR_PATH=%_SRC_DIR_PATH:\\=\%
@REM create output target path.
@CALL SET _TGT_FILR_PATH=%%_SRC_FILR_PATH:%_SRC_DIR_PATH%=%_CUR_DIR_PATH%%%
@REM trace
@REM @ECHO _CUR_DIR_PATH = %_CUR_DIR_PATH%
@REM @ECHO _SRC_DIR_PATH = %_SRC_DIR_PATH%
@REM @ECHO _SRC_FILR_PATH = %_SRC_FILR_PATH%
@REM @ECHO _TGT_FILR_PATH = %_TGT_FILR_PATH%
@REM copy file to target path from source path.
@ECHO F | xcopy /Y /I /F "%_SRC_FILR_PATH%" "%_TGT_FILR_PATH%"
@REM remove source file
del "%_SRC_FILR_PATH%"
@GOTO :EOF
@REM ----------------------------------------------------------------------------------------------
@REM -- sub_proc
@REM -- arg[1] : command
@REM ----------------------------------------------------------------------------------------------
:sub_proc
@SET SRC_DIR=D:\sys\Dropbox\private\medias\radio\ag
@REM @SET SRC_DIR=D:\tmp\agmv\dropbox\ag
@SET EXEC_BAT=%~dpnx0
@ECHO.
@ECHO [sub_proc]
@ECHO "%0" -list "%SRC_DIR%"
@FOR /F "delims=;" %%A IN ('CALL "%EXEC_BAT%" -list "%SRC_DIR%"') DO @(
@CALL "%EXEC_BAT%" -move "%SRC_DIR%" "%%A"
)
@GOTO :EOF
@REM ----------------------------------------------------------------------------------------------
@REM -- sub_main
@REM ----------------------------------------------------------------------------------------------
:sub_main
@IF "%~1" == "-list" (
@CALL :sub_list "%~2"
)
@IF "%~1" == "-move" (
@CALL :sub_move "%~2" "%~3"
)
@IF "%~1" == "" (
@CALL :sub_proc
)
@ENDLOCAL
move files recursive to directory from directory, keeping sub directory tree.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment