Ruby 文件操作与代码块使用指南
1. 文件查找相关方法
在 Ruby 中,我们可以定义一些实用的文件查找方法,以下是几个常见的示例:
- 查找可能由 Emacs 会话遗留的文件 :
# Finds files that were probably left behind by emacs sessions.
def emacs_droppings(*paths)
Find.match(*paths) do |p|
(p[-1] == ?~ and p[0] != ?~) or (p[0] == ?# and p[-1] == ?#)
end
end
- 查找大于特定大小的文件 :
# Finds all files that are larger than a certain threshold. Use this to find
# the files hogging space on your filesystem.
def bigger_than(bytes, *paths)
Find.match(*paths) { |p| File.lstat(p).size > bytes }
end
- 查找最近修改过的文件 :
Ruby 文件操作与代码块使用指南
超级会员免费看
订阅专栏 解锁全文

被折叠的 条评论
为什么被折叠?



