Publish folders to web site after batch backup of folders and files

Time:2020-1-11

First, back up all folders and files under “D: \ project 1” under “C: \ website” to “D: \ backup 2012-9-1-52647”, and then publish “D: \ project 1” to “C: \ website”.
usage
Backupandpublish.bat “D: \ project 1”

Copy codeThe code is as follows:
@echo off
set SourceDir=%1
set now=%date:~0,4%-%date:~5,2%-%date:~8,2%-%time:~0,2%%time:~3,2%%time:~6,2%
:: parameters
Set destdir = “C: \ website”
Set backdir = “D: \ backup% now%”
echo.
Echo is backing up
call:Backup %SourceDir% %DestDir% %BackDir%
echo.
Echo is publishing
call:Publish %SourceDir% %DestDir%
goto :eof
:: main program
:Backup
setlocal enabledelayedexpansion
set SourceDir=%~1
set DestDir=%~2
set BackDir=%~3
:: calculate source path length
set SourceDirLen=0
set SourceDirStr=%SourceDir%
:next1
if not “%SourceDirStr%”==”” (
set /a SourceDirLen+=1
set “SourceDirStr=%SourceDirStr:~1%”
goto :next1
)
:: Backup
for /r “%SourceDir%” %%i in (*.*) do (
set BackPath=%%~dpi
set BackPath=%BackDir%!BackPath:~%SourceDirLen%!
set DestPath=%%i
set DestPath=%DestDir%!DestPath:~%SourceDirLen%!
set BackFilePath=%%i
set BackFilePath=%BackDir%!BackFilePath:~%SourceDirLen%!
echo !DestPath!
xcopy “!DestPath!” “!BackPath!” /r /y >nul 2>nul
If not exist “! Backfilepath!” (echo backup copy failed)
)
for /r “%SourceDir%” %%i in (\) do (
set SourcePath=%%i
set SourcePath=!SourcePath:~0,-1!
set BackPath=%BackDir%!SourcePath:~%SourceDirLen%!
md “!BackPath!” >nul 2>nul
)
setlocal disabledelayedexpansion
goto :eof
:: issue
:Publish
set SourceDir=%1
set DestDir=%2
xcopy %SourceDir% %DestDir% /r /y /i /e
goto :eof