遍历文件夹中的特定文件 [ruby 遍历 文件夹 traverse]

今天客户要求把所有的页面和JavaScript中的提示行信息按
模块,中文,英文的格式
全部摘出来写个excel,为了检查英文是否“地道”

我设计的那部分系统的所有字符串资源都统一放在一个文件中,比较好处理
但是同事写代码时,所有字符串都写在出现的地方
手工一个一个来那可费死劲了,还容易遗漏

于是写了一个脚本 extract_alert.rb

 

require "find"
Find.find('./') do |path|
        if not File.directory?path and path[/\.jsp$/] then
                found_line = []
                File.open("#{Dir.pwd}#{path[1..path.size]}","r").each_with_index do|line,lno|
                        if line=~/[^\/]alert/ then
                                found_line<<"#{lno}:\t#{line.strip}"
                        end
                end
                if found_line.size!=0 then
                        puts path
                        puts found_line
                        puts "\n"
                end
        end
end

 本来说写一个遍历文件夹的函数,查了下Ruby Cookbook,原来Ruby早就写好了一个Find模块,使用起来很方便

extract_alert.rb>>a.txt

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值