惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

C
CXSECURITY Database RSS Feed - CXSecurity.com
Stack Overflow Blog
Stack Overflow Blog
月光博客
月光博客
T
Threat Research - Cisco Blogs
小众软件
小众软件
有赞技术团队
有赞技术团队
酷 壳 – CoolShell
酷 壳 – CoolShell
Apple Machine Learning Research
Apple Machine Learning Research
C
Cyber Attacks, Cyber Crime and Cyber Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
T
Tailwind CSS Blog
Cisco Talos Blog
Cisco Talos Blog
V
V2EX
博客园 - 【当耐特】
C
Cybersecurity and Infrastructure Security Agency CISA
Hugging Face - Blog
Hugging Face - Blog
The Cloudflare Blog
The Last Watchdog
The Last Watchdog
Simon Willison's Weblog
Simon Willison's Weblog
T
Threatpost
S
Secure Thoughts
O
OpenAI News
P
Proofpoint News Feed
S
SegmentFault 最新的问题
Forbes - Security
Forbes - Security
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Application and Cybersecurity Blog
Application and Cybersecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Last Week in AI
Last Week in AI
宝玉的分享
宝玉的分享
Scott Helme
Scott Helme
T
Tenable Blog
A
Arctic Wolf
L
LINUX DO - 热门话题
爱范儿
爱范儿
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
www.infosecurity-magazine.com
www.infosecurity-magazine.com
V
Visual Studio Blog
Hacker News: Ask HN
Hacker News: Ask HN
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
博客园 - Franky
WordPress大学
WordPress大学
Know Your Adversary
Know Your Adversary
博客园_首页
雷峰网
雷峰网
IT之家
IT之家
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
H
Heimdal Security Blog

博客园 - 阿武

Moto G 通话没声音 Android 手机技巧 一个Java程序的生死旅程 精妙语录 【Windows Phone 7】【软件发布】深圳通助手 & 深圳长途汽车查询 & 深圳地铁通 [C++ Primer] Passing an array to a function by reference/pointers -- sample 京东自动抢购机 64位的处理器支持多大的内存? 将.NET Entity Framework 的 Cache模块移植到JAVA平台 做快乐的程序员 Q 语言初学者系列:(3)Lists 初级 KDB+性能分析:内存篇 Q 语言初学者系列:(2)基本数据类型 Q 语言初学者系列:(1)开门篇 熟悉的感觉 盘点自己两年来走过的路 [JAVA]你见过这样的switch吗? - 阿武 - 博客园 网站上图片"另存为" 为什么是 bmp 格式 经实验, 网线两端都接在交换机上并不会烧毁交换机
【Ruby】删除旧文件
阿武 · 2011-06-20 · via 博客园 - 阿武

一个删除旧文件的函数,通常用于删除较老的log文件。

 module FileUtils2
    ONE_DAY_SECONDS 
= 60*60*24
    
# remove the old files, return the number of files that removed.    
    def remove_old_files(dir_path, days_ago)
        count 
= 0    
        dir_path2 
= dir_path + File::ALT_SEPARATOR unless dir_path.end_with?(File::ALT_SEPARATOR)
        d 
= Dir.new dir_path2    

        now 

= Time.now
        
        d
.each  {|filename|     
            
next if filename == '.' or filename == '..'

            file_path 

= dir_path2 + filename
            
next if File.directory?(file_path)
            
            f 
= File.new(file_path)
            diff 
= now.to_i - f.mtime.to_i
            f
.close
            day 
= diff/ONE_DAY_SECONDS
            
            
next if day <= days_ago
            
            File
.delete(file_path)
            puts 
"Delete: #{file_path}." 
            count 
+= 1
        }
        
return count
    end
end