赞 | 641 |
VIP | 62 |
好人卡 | 144 |
积分 | 320 |
经验 | 110435 |
最后登录 | 2024-4-28 |
在线时间 | 5081 小时 |
Lv5.捕梦者
- 梦石
- 0
- 星屑
- 32028
- 在线时间
- 5081 小时
- 注册时间
- 2012-11-19
- 帖子
- 4877
|
本帖最后由 芯☆淡茹水 于 2018-1-26 21:57 编辑
#比如 Graphics/Pictures 文件夹里所有文件
all_files = Dir::entries("Graphics/Pictures")
#所有 png 文件
all_png_files = all_files.find_all{|name| name.split(".").pop == "png"}
#所有 txt 文件
all_txt_files = all_files.find_all{|name| name.split(".").pop == "txt"}
#其它以此类推。判断文件类型目前就只想到这一个方法,不知道会不会判错。
#也可以方便点写个函数
def Lookup_file(path, file_type)
return Dir::entries(path).find_all{|name| name.split(".").pop == file_type}
end
#要查找就直接用写的函数,比如图片的:
Lookup_file("Graphics/Pictures", "png")
|
评分
-
查看全部评分
|