Archiving Files
Learn how to add an archiving feature to the walk tool.
We'll cover the following...
Before deleting files that are consuming too much space, we might want to back them up in a compressed form so we can keep them around in case we need them later. Let’s add an archiving feature to the walk tool to enable this feature.
Importing the compress/gzip
package
To add this new feature, we’ll use these standard library packages:
compress/gzip
to compress data using the gzip format.io
, which provides functions to help with Input/Output operations such as copying data.
The package io
is already included in the import
list. We add the compress/gzip
package to the import
list in the file actions.go
:
import ("compress/gzip""fmt""io""log""os""path/filepath")
Importing the gzip package
Adding the archiveFile()
function
We define the new action function archiveFile(destDir, root,
...