Skip to content

Instantly share code, notes, and snippets.

@si1en2i0
Created June 11, 2012 08:58
Show Gist options
  • Save si1en2i0/2909171 to your computer and use it in GitHub Desktop.
Save si1en2i0/2909171 to your computer and use it in GitHub Desktop.
根据yaml文件的内容打包指定的文件
#!/usr/bin/env ruby
#coding: utf-8
require 'yaml'
require 'fileutils'
config_file_path = 'package.yaml'
# get related diretories information & prepare
src = Dir.getwd
dst = File.expand_path('_package', src)
Dir.mkdir(dst) if not File.exist?(dst)
# read structure data
files = YAML.load_file(config_file_path)
# fetch files and keep their hierarchy
files.each do |v|
dir = File.expand_path(File.dirname(v), dst)
FileUtils.mkdir_p(dir) if not File.exist?(dir)
FileUtils.cp_r(File.expand_path(v, src), File.expand_path(v, dst))
end
- dir1
- dir2
- dir3/file1.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment