@echo off
rem thist program move files to dirs by date of file
rem SET path with files that need to be moved
set frompath=%~1
set topath=%~2
if "%~3" == "" (
set filemask=*.*
) else (
set filemask=%~3
)
rem set dateformat for OS where running script
rem DD.MM.YYYY or YYYY/MM/DD e.t.c.
rem For DD.MM.YYYY set dateformat = 1
rem For YYYY/MM/DD set dateformat = 2
set dateformat=1
if not exist %frompath% (
echo Path "%frompath%" is not exist
pause
goto USAGE
)
if not exist %topath% (
echo "%frompath%" is not exist
pause
goto USAGE
)
echo.
echo Start at %date% %time% on %computername%
echo From dir - %frompath%
echo To dir - %topath%
echo Mask - %filemask%
echo ----------------------------------------------------------------------
PUSHD %frompath%
FOR %%f IN (%filemask%) do (
rem echo %%f %%~tf
FOR /F "eol= tokens=1,2,3 delims=/. " %%i IN ("%%~tf") DO (
if "%dateformat%"=="1" (
echo Moving %%f to %topath%\%%k\%%j\%%i
call :MOVE "%topath%\%%k\%%j\%%i" "%%f"
) else if "%dateformat%"=="2" (
echo Moving %%f to %%i\%%j\%%k
call :MOVE "%topath%\%%i\%%j\%%k" "%%f"
)
)
)
POPD
echo ----------------------------------------------------------------------
echo End at %date% %time%
goto quit
:MOVE
if "%~1"=="" goto quit
if "%~2"=="" goto quit
rem echo %~1 %~2
if NOT EXIST "%~1" md "%~1"
if NOT EXIST "%~1\%~2" (
rem move "%~2" "%~1\%~2"
copy "%~2" "%~1\%~2"
del /q "%~2"
) else echo File exist with this name "%~1\%~2". Not moved.
goto quit
:USAGE
echo %0 [from_dir] [to_dir]
echo Move files by (default *.*) from [from_dir]
echo to [to_dir]\[year_of_file]\[month_of_file]\[day_of_file]
echo For change date format depend OS date format - change in script "dateformat"
:quit
|