From 3efec5c85f966bd8ad1ffee093399484cc1ff39d Mon Sep 17 00:00:00 2001 From: taynpg Date: Thu, 17 Apr 2025 16:56:43 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E4=B8=80=E4=B8=AA=E5=A4=8D?= =?UTF-8?q?=E5=88=B6=E5=A4=87=E4=BB=BD=E6=96=87=E4=BB=B6=E5=A4=B9=E7=9A=84?= =?UTF-8?q?=E6=89=B9=E5=A4=84=E7=90=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- os/backupdir.bat | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 os/backupdir.bat diff --git a/os/backupdir.bat b/os/backupdir.bat new file mode 100644 index 0000000..d92935e --- /dev/null +++ b/os/backupdir.bat @@ -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 \ No newline at end of file