递归目录

def get_all_include_directory(home,result=nil)  
    result=[] unless result#传进来的result参数为空,则自定义一个变量
    Dir.entries(home).each do |sub|       
        if  sub!=".." && sub!="."
            if File.directory?("#{home}/#{sub}")
                get_all_include_directory("#{home}/#{sub}", result)#递归查询
            elsif (sub=~/\.h$/) && result.count(home) == 0#此文件夹保护.h文件且未记录到搜索结果中
                result<<"#{home}"
            end       
        end  
    end
end

mydirs = []
mystr = []

ARGV.each do |arg|#参数中传过来的目录
    if File.directory?(arg)
        mydirs[mydirs.size] = arg
    end
end

if 0 == mydirs.size#参数中无目录,默认使用当前目录
    mydirs[0] = Dir.pwd
end

mydirs.each do |dir|
    get_all_include_directory("#{dir}",mystr)
end

puts mystr

 

function applycmd(dir, exe, pattern)
    if (not exe) or (not dir) then
        return
    end
    local tmpfile=os.tmpname()
    os.execute("ls -l".." "..dir.."|grep r|awk '{print $9}'|tee "..tmpfile)
    for line in io.lines(tmpfile) do
        repeat
            --[[
            print(">>>")
            print(dir)
            print(line)
            print("<<<")
            --]]
            local ret=os.execute("cd "..line.." 2>/dev/null")
            if 0==ret then
                applycmd(dir.."/"..line,exe,pattern)
                break
            end
            local doit=true
            if pattern then
                doit=string.find(line,pattern)
            end
            if doit then
                os.execute(exe.." "..dir.."/"..line)
            end
        until true
    end
    os.remove(tmpfile)
end

applycmd(".","dos2unix",".lua")

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值