24、Ruby 文件操作与代码块使用指南

Ruby 文件操作与代码块使用指南

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
  • 查找最近修改过的文件

                
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值