Copy all files and folders except few in Ruby -


i wondering if can use fileutils.cp_r method copy files , directories source target except .tar files. can give me example better understanding?

thanks

sure you'd have implement kind of filter first this:

[8] pry(main)> dir.glob("**/*") => ["bin", "code_of_conduct.md", "gemfile", "gemfile.lock", "hello.tar", "lib", "license.txt", "mygem.gemspec", "rakefile", "readme.md", "spec"] 

that gave files in directory , subsequent directories(thanks ndn tip), let's filter out hello.tar:

files = dir.glob("**/*").reject { |file| file.end_with?(".tar") } 

now can pass array filteutils::cp_r

fileutils.cp_r(files, destination) 

Comments

Popular posts from this blog

html - Firefox flex bug applied to buttons? -

html - Missing border-right in select on Firefox -

c# - two queries in same method -