Tar for files?

Note that a tar file isn’t compressed in the sense of a zip or other file. It merely wraps the given files into a single tarball, it doesn’t try to minimize its size.

Tar.create accepts a predicate argument, so you can do

Tar.create(dir_containing_files, tarball_destination) do path
  basename(path) in ["myfile1", "myfile2"]
end

This will look in dir_containing_files, but only include myfile1 and myfile2 in the created tarball, and exclude any other files in the directory.

You can include any logic in the do block, so if your generated filenames have a pattern to them, you can select based on that too.

1 Like