开发者社区 问答 正文

Ruby中文目录的问题?报错

Ruby如果指定中文路径(如"d:/中文目录"),历遍目录会报错,如果指定路径包含中文(如"d:/doc/中文目录"),而子目录中还有中文目录,历遍也会报错。好像是个bug,求证。还是需要转换,怎么转,求教


#encoding:utf-8
require 'find'
require 'pathname'
dirs = ["d:/打呼噜"]

for dir in dirs
    Find.find(dir) do |path|
    if FileTest.directory?(path)
    else
        p path.encode('gbk')	
	end
	end
end




展开
收起
爱吃鱼的程序员 2020-06-14 20:54:32 722 分享
分享
版权
举报
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB
    #-*-coding:utf-8-*-dirs=["z:/打呼噜"]dirs.eachdo|dir|Dir.glob(dir+"/*").eachdo|path|ifFile.directory?(path)elseputspathendendend



    具体报什么?建议截图直接用Dir.glob吧,那个Find可能有BUG,不清楚贴了问题解决了,谢谢
    2020-06-14 20:54:49 举报
    赞同 评论

    评论

    全部评论 (0)

    登录后可评论
问答分类:
问答标签:
问答地址: