顯示具有 batch 標籤的文章。 顯示所有文章
顯示具有 batch 標籤的文章。 顯示所有文章

2022/10/31

7zip 壓縮檔案指令

為了想要定期把一些檔案壓縮成一個檔案,所以就想到要用batch加排程的方式。

7zip有提供相關的指令可以做

指令如下,

7z a d:\backup[%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%].7z  @d:\list.txt 

第一欄(7z) - 就是執行程式的名稱,最好是用完整路徑

第二欄(a) - 就是要壓縮的意思

第三欄(d:\xxx) - 就是壓縮檔的名稱,上面的範例是檔名會自動產生當天的日期,後面的副檔名也可以改用zip

第四欄(@:xxx) - @後面要接一個文字檔,這個文字檔裡就列出要壓縮的檔案存放的路徑,所以有3個不同資料夾的檔案要壓在一起,就把三個路徑分三行存在文字檔裡就行了。

以上就是batch檔的內容。



7zip File Compression Command


In order to periodically compress files into a single archive, I decided to use batch scripting along with scheduled tasks. Fortunately, 7zip provides relevant commands to achieve this.

The command is as follows:

7z a d:\backup[%DATE:~0,4%-%DATE:~5,2%-%DATE:~8,2%].7z @d:\list.txt

Here is a breakdown of the command:

The first field (7z) represents the name of the executable program. It is recommended to use the full path to the program.

The second field (a) indicates the action of compressing.

The third field (d:\xxx) specifies the name of the compressed file. In the example above, the file name will be automatically generated based on the current date. You can also change the file extension to .zip if desired.

The fourth field (@:xxx) specifies a text file. This text file contains the paths of the files to be compressed. So, if you have files from three different folders that need to be compressed together, you can list the three paths on separate lines in the text file.

The above instructions can be included in a batch file to automate the process.