我每天都有一个蝙蝠脚本 1)创建一个包含今天日期的文件夹 2)将一些文件复制到新文件夹
如果文件夹超过30天,我想让脚本也删除文件夹及其中的所有文件。
@echo off
echo
echo ------------------------------------------------------------------
echo Daily script that backs ups important files
echo ------------------------------------------------------------------
echo ------------------------------------------------------------------
echo Calcualtion of date
for /f "delims=" %%a in ('wmic OS Get localdatetime ^| find "."') do set "dt=%%a"
set "YY=%dt:~2,2%"
set "YYYY=%dt:~0,4%"
set "MM=%dt:~4,2%"
set "DD=%dt:~6,2%"
set "HH=%dt:~8,2%"
set "Min=%dt:~10,2%"
set "Sec=%dt:~12,2%"
set datestamp=%YYYY%%MM%%DD%
set timestamp=%HH%%Min%%Sec%
set fullstamp=%YYYY%-%MM%-%DD%_%HH%-%Min%-%Sec%
echo ------------------------------------------------------------------
echo Make new Backup folder
md G:\IMS-%fullstamp%
md G:\Backup\IMS-%fullstamp%\Services
echo ------------------------------------------------------------------
echo Copy files into backup folder
xcopy /s /y C:\Services G:\IMS-%fullstamp%\Services
echo ------------------------------------------------------------------
echo Delete old backup folders if older than 30 days