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")