如何从打开命令中查找文件路径
我需要获取 fo 变量中的文件路径,以便可以将路径传递给 unzip_file 函数。我如何获得这里的路径?
url = 'http://www.dtniq.com/product/mktsymbols_v2.zip'
open(url, 'r') do |fo|
puts "unzipfile "
unzip_file(fo, "c:\\temp11\\")
end
I need to get the path of the file in fo variable so that i can pass the path to the unzip_file function. how do i get the path here?
url = 'http://www.dtniq.com/product/mktsymbols_v2.zip'
open(url, 'r') do |fo|
puts "unzipfile "
unzip_file(fo, "c:\\temp11\\")
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
至于如何做到这一点,我会这样做:
找出我正在处理的对象的类
<前><代码>ruby-1.9.2-p290 :001> tmp_file = open('tmp.txt', 'r')
=> #<文件:tmp.txt>
ruby-1.9.2-p290:001> tmp_file.class
=>文件
去查找该类的文档
Google 搜索:ruby 文件
返回
Class: File ruby-doc.org
=>; www.ruby-doc.org/core/classes/File.html查看方法。有一个叫做
path
->看起来很有趣如果我现在还没有找到答案,那么
大多数时候
1..3
应该可以满足您的需求。一旦您学会阅读文档,您就可以更快地完成工作。它只是试图克服刚开始时进入文档的困难。In terms of how to do it I would do this:
Find out the class of the object I am dealing with
Go look up the documentation for that class
Google Search : ruby file
Which returns
Class: File ruby-doc.org
=> www.ruby-doc.org/core/classes/File.htmlLook at the methods. There is one called
path
-> looks interestingIf I haven't found an answer by now then
Most of the time
1..3
should get you what you need. Once you learn to read the documentation you can do things a lot quicker. It's just trying to overcome how difficult it is to get into the docs when you first start.块中的
fo
应该是Tempfile
因此您可以使用路径
方法:The
fo
in your block should be aTempfile
so you can use thepath
method: