Sha256: b11291e0b6de26c2592e3550184746bb2763ed10db78fddb06851f2855cb9677

Contents?: true

Size: 1021 Bytes

Versions: 2

Compression:

Stored size: 1021 Bytes

Contents

#!/usr/bin/env ruby
# -*- coding: binary -*-

msfbase = __FILE__
while File.symlink?(msfbase)
	msfbase = File.expand_path(File.readlink(msfbase), File.dirname(msfbase))
end
inc = File.dirname(msfbase) + '/../../..'
$:.unshift(inc)

require 'rex/zip'

out = "test.zip"
dir = "/var/www"


def add_file(zip, path)
	zip.add_file(path)
end


#
# If it's a directory, Walk the directory and add each item
#
def add_files(zip, path, recursive = nil)

	if (not add_file(zip, path))
		return nil
	end

	if (recursive and File.stat(path).directory?)
		begin
			dir = Dir.open(path)
		rescue
			# skip this file
			return nil
		end

		dir.each { |f|
			next if (f == '.')
			next if (f == '..')

			full_path = path + '/' + f
			st = File.stat(full_path)
			if (st.directory?)
				puts "adding dir  #{full_path}"
				add_files(zip, full_path, recursive)
			elsif (st.file?)
				puts "adding file #{full_path}"
				add_file(zip, full_path)
			end
		}
	end
end


zip = Rex::Zip::Archive.new
add_files(zip, dir, TRUE)
zip.save_to(out)

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
librex-0.0.68 lib/rex/zip/samples/recursive.rb
librex-0.0.66 lib/rex/zip/samples/recursive.rb