将提取的zip文件内容存储在不同的目录中?(Storing extracted content of the zip file in different directory?)

编程入门 行业动态 更新时间:2024-10-28 02:23:57
将提取的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 end

This 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 here

Change 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

本文发布于:2023-07-26 02:11:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1269548.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文件   内容   目录中   zip   Storing

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!