i_love_ruby 发表于 2011-11-04 11:23

如何快速最优的获取文件的路径

file_path="D:/android_source/fdmakm/你好/Ruby/w/ok.txt"

如何 获取 文件的路径 "D:/android_source/fdmakm/你好/Ruby/w/"?
用最优的方式?

谢谢!

coolesting 发表于 2011-11-04 12:04

本帖最后由 coolesting 于 2011-11-04 12:09 编辑

gsub, sqlit, Dir[]

i_love_ruby 发表于 2011-11-04 13:38

回复 2# coolesting


    谢谢,其余的 童鞋 还有没有别的方法呀?

coolesting 发表于 2011-11-04 15:00

path="D:/android_source/fdmakm/你好/Ruby/w/ok.txt"

#这是官方的写法
File.split(path).first

#D:/android_source/fdmakm/你好/Ruby/w

i_love_ruby 发表于 2011-11-05 01:36

回复 4# coolesting


    可是,我这边一直报错:

SyntaxError: E:\eclipse-ws\helloword-ruby\test_map.rb:157: invalid multibyte char (US-ASCII)。
编码 问题的 这种情况如何避免呢?

i_love_ruby 发表于 2011-11-05 01:56

回复coolesting


    可是,我这边一直报错:

SyntaxError: E:\eclipse-ws\helloword-ruby\test_ ...
i_love_ruby 发表于 2011-11-05 01:36 http://bbs.chinaunix.net/images/common/back.gif


    解决了,一般在文件的开头加上:
#encoding:utf-8
页: [1]
查看完整版本: 如何快速最优的获取文件的路径