将提取的zip文件内容存储在不同的目录中?(Storing extracted content of the zip file in different directory?)
这工作正常,但我的问题是,如何将zip文件的内容解压缩到另一个目录?
require 'rubygems' require 'zip/zip' Zip::ZipFile.open("j.zip") do |zipfile| zipfile.each do |file| file.extract end endThis is working fine but my question is, how do I extract the zip file's content into a different directory?
require 'rubygems' require 'zip/zip' Zip::ZipFile.open("j.zip") do |zipfile| zipfile.each do |file| file.extract end end最满意答案
更改工作目录
可能有其他方法可以解决此问题,但最明显的一个方法是使用Dir #chdir更改当前工作目录。 例如,要将文件解压缩到/tmp :
old_pwd = Dir.pwd Dir.chdir '/tmp' # run your commands hereChange the Working Directory
There may be other ways to address this issue, but one of the most obvious is to change the current working directory with Dir#chdir. For example, to extract your files into /tmp:
old_pwd = Dir.pwd Dir.chdir '/tmp' # run your commands here更多推荐
zip,require,extract,'rubygems',文件,电脑培训,计算机培训,IT培训"/> <m
发布评论