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

推荐订阅源

Y
Y Combinator Blog
MyScale Blog
MyScale Blog
Recent Announcements
Recent Announcements
酷 壳 – CoolShell
酷 壳 – CoolShell
GbyAI
GbyAI
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
N
Netflix TechBlog - Medium
V
V2EX
MongoDB | Blog
MongoDB | Blog
Microsoft Security Blog
Microsoft Security Blog
博客园 - 三生石上(FineUI控件)
Stack Overflow Blog
Stack Overflow Blog
U
Unit 42
B
Blog
Microsoft Azure Blog
Microsoft Azure Blog
博客园_首页
H
Help Net Security
D
DataBreaches.Net
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
阮一峰的网络日志
阮一峰的网络日志
T
The Blog of Author Tim Ferriss
C
Check Point Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报

博客园 - 乱草

仓央嘉措:如果爱是一场修行 重庆旅游 nothing qq签名 Linux也玩远程桌面(VNC) 五一海峡车展--汽车篇 五一福州海峡车展-美眉篇 ipad2 在购一台? 一月份在上海的几张照片 吉他英雄老爹 亲爱的宝宝 the daily 发布了 MSN中文网公布了"2010年度十大MSN经典签名" 色彩的魔力(转贴) 9月杭州 9月在上海的几张照片 最近被一个socket占用搞的头疼,记录一下netstat用法 nothing pl/sql 注册码
历遍目录,读取文件,然后将文件中的固定行替换掉
乱草 · 2011-11-29 · via 博客园 - 乱草

应该有很多方法可以更加简单,只是太久没有写程序了,赶鸭子上架了 

require 'iconv'

def myreplay(filename,tt)

    ##建立另外一个目录,将文件产生到新的目录中

    file=File.open('D://bak/tmp2/' + tt + '/' + filename,'w')

   i=0

   message=''

   File.open('D://bak/tmp/' + tt + '/' + filename).each do |f|

       message=f

           if(f=~/<ErrorFieldCount>0<\/ErrorFieldCount>/)

           (

                 file.print '<ErrorFieldCount>1</ErrorFieldCount>'

file.print "\n"

           )

       else

           (

            file.puts message

           )

       end

   end

end

def indirp(dirname)

dirp2 =Dir.open("D://bak/tmp/" + dirname)

 for m in dirp2

 case m   

                  when /^\./, /~$/, /\.o/,/.rb/,/.dat/ 

                  else  

 ##开始调用替换函数

#myreplay(m,dirname)

puts dirname 

puts m

myreplay(m,dirname)

                  end   

 end

end

dirp = Dir.open("d://bak/tmp")   

for f in dirp   

  case f   

  when /^\./, /~$/, /\.o/,/.rb/,/.dat/ 

  else  

 ##进入这个目录中

 indirp(f)

  end   

end   

dirp.close