开发过程中要增加预编译头文件,一个个文件加太麻烦,于是用ruby写了一个小程序,批量加,效果不错,呵呵
workdir="D:/work/ipoone/BOXClient/BOXClient/classes" #宸ヤ綔鐩綍
def traverse_dir(file_path)
if File.directory? file_path
Dir.foreach(file_path) do |file|
if file!="." and file!=".."
traverse_dir(file_path+"/"+file){|x| yield x}
end
end
else
yield file_path
end
end
def addHeadFile(file)
iofile=File.open(file,"r")
filestring=iofile.read
filestring.insert(0,'
#include "stdHead.h"
')
iowrite=File.open(file,"w")
iowrite.write(filestring)
end
traverse_dir(workdir){|f|
if File.fnmatch("*.cpp",f)
addHeadFile(f)
puts f
end
}