@echo off
setlocal enabledelayedexpansion
rem initialize all variables
set counter=1
set groupnumber=1
rem change groupcount value if you want a different number of files per zip
set groupcount=3
set zipfilenamePrefix=archive
rem start looping over...
for %%f in (*) do (
if not "%%f"=="%~nx0" (
set fileList=!fileList! %%f
set /a reminder=!counter!%%!groupcount!
if !reminder! equ 0 (
set zipfilename=archive!groupnumber!.tz
echo Zipping files: !fileList! into !zipfilename!
rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
set /a groupnumber=!groupnumber!+1
set fileList=
)
set /a counter=counter+1
)
)
rem there could be some left over files - last group may be less than 3 files
if !reminder! equ 0 (
set zipfilename=archive!groupnumber!.tz
echo Zipping into files: !fileList! !zipfilename!
rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
)
Q
如何運行下面
-1
A
回答
0
腳本上面的代碼沒有做任何事情。
起初,你需要做的評論說什麼(添加存檔實用程序)。然後將代碼保存到.bat
或.cmd
文件並執行該操作。
0
下面是創建使用7-Zip的ZIP文件的例子。修復程序已應用並添加了更多配置變量。
它會創建與每個ZIP(經由groupcount
可變配置的)最大的100個文件的多個ZIP文件,並保存在zip文件作爲爲MyBackup ##。拉鍊其中##是順序號。
打字MAKEZIPS
單獨沒有任何參數顯示用法。在文件夾歸檔C:\My Data
的所有文件(不包括子文件夾),並把ZIP文件D:\My Backup
一個例子:
MAKEZIPS "C:\My Data" "D:\My Backup"
注意:不要把ZIP文件到同一文件夾與源文件夾,或者它可能會導致無休止循環。
如果您使用其他存檔程序(例如:WinRAR),則必須更改程序路徑及其參數。
MAKEZIPS.BAT
:
@echo off
setlocal enabledelayedexpansion
rem initialize all variables
rem ***config start***
rem change groupcount value if you want a different number of files per zip
set groupcount=100
rem change zipfilenamePrefix value if you want a different base file name
set zipfilenamePrefix=MyBackup
rem change zipfileExt value if you are creating other archive type
set zipfileExt=zip
rem ***config end***
set counter=0
set groupnumber=1
if "%~2"=="" (
echo Usage: MAKEZIPS {Source Folder} {Target Folder}
goto :eof
)
if not exist "%~1\nul" (
echo Source folder not found.
goto :eof
)
if not exist "%~2\nul" (
echo Target folder not found.
goto :eof
)
pushd %2
rem start looping over...
for %%f in (*) do (
if not "%%f"=="%~nx0" (
set fileList=!fileList! "%%f"
set /a counter=!counter!+1
set /a reminder=!counter!%%!groupcount!
if !reminder! equ 0 (
set zipfilename="%~1\%zipfilenamePrefix%!groupnumber!.%zipfileExt%"
echo Zipping files: !fileList! into !zipfilename!
rem your zipping utility goes here: input = !fileList! and output = !zipfilename!
"C:\Program Files\7-Zip\7z.exe" a !zipfilename! !fileList!
if not exist !zipfilename! (
echo ZIP creation failed.
goto :eof
)
set /a groupnumber=!groupnumber!+1
set fileList=
)
)
)
rem there could be some left over files - last group may be less than 3 files
if %reminder% gtr 0 (
set zipfilename="%~1\%zipfilenamePrefix%%groupnumber%.%zipfileExt%"
echo Zipping into files: %fileList% %zipfilename%
rem your zipping utility goes here: input = %fileList% and output = %zipfilename%
"C:\Program Files\7-Zip\7z.exe" a %zipfilename% %fileList%
if not exist %zipfilename% echo ZIP creation failed.
)
popd
相關問題
- 1. 如何運行下面的jQuery代碼
- 2. 如何在android中運行時更改下面的目標?
- 3. 如何我運行下面的循環,使用R
- 4. hashmap如何在下面的場景中運行?
- 5. 如何在預覽模式下在頁面上運行相機?
- 6. 如何在頁面爲index.html的情況下運行jquery腳本
- 7. 如何僅在特定條件下異步運行ASP.NET頁面?
- 8. java.lang.IllegalStateException occour而下面的代碼運行
- 9. 當我運行下面的Java代碼
- 10. 試圖運行下面的程序
- 11. 運行 - 在下面的代碼
- 12. 在Linux下運行ActiveX頁面
- 13. 如何在php頁面上運行dojo
- 14. 如何在後臺運行ASP.NET頁面?
- 15. 如何在netbeans裏面運行python?
- 16. node.Js - 如何運行不同的頁面?
- 17. 如何在IIS後面運行紅隼
- 18. 如何從桌面圖標運行flexdashboard
- 19. 如何運行一個頁面
- 20. 如何在Netbeans中運行Php頁面
- 21. 如何在CAKEPHP中運行PHP頁面?
- 22. 如何運行裏面的makefile
- 23. 如何從ASP頁面運行sqlcmd.exe?
- 24. python解釋器如何在下面的代碼中逐行運行代碼?
- 25. 如何運行以下代碼
- 26. 以下程序如何運行?
- 27. 如何在su下運行sudo?
- 28. 如何在mod_perl2下運行Devel :: Cover?
- 29. 如何在條件下運行「has_secure_password」?