添加一个复制备份文件夹的批处理
This commit is contained in:
parent
43bc2fd733
commit
3efec5c85f
37
os/backupdir.bat
Normal file
37
os/backupdir.bat
Normal file
@ -0,0 +1,37 @@
|
||||
@echo off
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
:: Set source and target directories (modify these paths)
|
||||
set "source_dir="
|
||||
set "target_base="
|
||||
|
||||
:: Get standardized timestamp using WMIC (format: YYYYMMDDHHMMSS)
|
||||
for /f "tokens=1-6 delims=." %%a in ('wmic os get LocalDateTime ^| find "."') do (
|
||||
set "datetime=%%a"
|
||||
)
|
||||
set "year=!datetime:~0,4!"
|
||||
set "month=!datetime:~4,2!"
|
||||
set "day=!datetime:~6,2!"
|
||||
set "hour=!datetime:~8,2!"
|
||||
set "minute=!datetime:~10,2!"
|
||||
set "second=!datetime:~12,2!"
|
||||
|
||||
:: Create timestamp with seconds (YYYYMMDDHHMMSS)
|
||||
set "timestamp=%year%%month%%day%%hour%%minute%%second%"
|
||||
set "target_dir=%target_base%\%timestamp%"
|
||||
|
||||
:: Create target directory
|
||||
if not exist "%target_dir%" (
|
||||
mkdir "%target_dir%"
|
||||
) else (
|
||||
echo Target directory already exists: %target_dir%
|
||||
pause
|
||||
exit /b 1
|
||||
)
|
||||
|
||||
:: Copy files
|
||||
echo Copying files from %source_dir% to %target_dir%...
|
||||
xcopy "%source_dir%\*" "%target_dir%\" /E /C /H /Y
|
||||
|
||||
echo Copy completed! Directory name: %timestamp%
|
||||
pause
|
Loading…
x
Reference in New Issue
Block a user