|
- @echo off
- setlocal enabledelayedexpansion
- :: 设置当前目录的路径
- set "NowPath=%CD%"
- :: 设置目标路径用于存放要压缩的文件和文件夹
- set "TargetPath=%NowPath%\new\temp_backup"
- if not exist "%TargetPath%" mkdir "%TargetPath%"
- :: 这里列出你想复制的文件夹和文件,确保路径是相对于NowPath的
- set "Copy_items=u\ test111.bat test111\xxx.bat test111\pcsofts.txt test111\web\ 3\up_down\down"
- for %%i in (%Copy_items%) do (
- if exist "%%i" (
- set "FullPath=%%~fi"
- set "RelativePath=%%i"
- if exist "%%i" (
- mkdir "%TargetPath%\!RelativePath!" 2>nul
- xcopy "%%i" "%TargetPath%\!RelativePath!" /I /E /Y
- ) else (
- set "RelativeDir=!RelativePath:%%~nxi=!"
- mkdir "%TargetPath%\!RelativeDir!" 2>nul
- copy "%%i" "%TargetPath%\!RelativeDir!\%%~nxi"
- )
- ) else (
- echo 提示: "%%i" 未找到.
- )
- )
- :: 设置压缩文件的名称和路径
- set "ZipFile=%SourcePath%\backup.zip"
- :: 设置7-Zip的完整路径
- set "ZipPath=C:\Program Files\7-Zip\7z.exe"
- :: 使用7-Zip压缩目标路径中的内容
- "%ZipPath%" a -r -tzip "%ZipFile%" "%TargetPath%\*" -mx=9 -y
- :: 检查压缩命令是否成功执行
- if %ERRORLEVEL% EQU 0 (
- echo 操作成功!
- ) else (
- echo 操作失败, 请检查!
- )
- :: 删除目标路径(取消注释下面一行以启用删除)
- :: rd /s /q "%TargetPath%"
- endlocal
- pause
复制代码 |
|