﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>语源科技BlogJava-大头的空间</title><link>http://www.blogjava.net/sxwailyc/</link><description /><language>zh-cn</language><lastBuildDate>Sun, 21 Jun 2026 15:49:40 GMT</lastBuildDate><pubDate>Sun, 21 Jun 2026 15:49:40 GMT</pubDate><ttl>60</ttl><item><title>XBAApp(体验版2008.9.21过期)</title><link>http://www.blogjava.net/sxwailyc/articles/221092.html</link><dc:creator>大头@</dc:creator><author>大头@</author><pubDate>Sat, 09 Aug 2008 23:09:00 GMT</pubDate><guid>http://www.blogjava.net/sxwailyc/articles/221092.html</guid><wfw:comment>http://www.blogjava.net/sxwailyc/comments/221092.html</wfw:comment><comments>http://www.blogjava.net/sxwailyc/articles/221092.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sxwailyc/comments/commentRss/221092.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sxwailyc/services/trackbacks/221092.html</trackback:ping><description><![CDATA[<p><a title="点此下载" href="/Files/sxwailyc/XBAApp.rar">点此下载</a>&nbsp;</p>
<img src ="http://www.blogjava.net/sxwailyc/aggbug/221092.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sxwailyc/" target="_blank">大头@</a> 2008-08-10 07:09 <a href="http://www.blogjava.net/sxwailyc/articles/221092.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>查找某目录下的所有文件并替换特定字符的脚本</title><link>http://www.blogjava.net/sxwailyc/articles/220817.html</link><dc:creator>大头@</dc:creator><author>大头@</author><pubDate>Fri, 08 Aug 2008 01:02:00 GMT</pubDate><guid>http://www.blogjava.net/sxwailyc/articles/220817.html</guid><wfw:comment>http://www.blogjava.net/sxwailyc/comments/220817.html</wfw:comment><comments>http://www.blogjava.net/sxwailyc/articles/220817.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/sxwailyc/comments/commentRss/220817.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/sxwailyc/services/trackbacks/220817.html</trackback:ping><description><![CDATA[前两天在工作上碰到要把某个文件夹(里面包含有多层的子文件夹)里的XML文件中的一些字符改成其它值的情况,想了想就自己用RUBY写了个脚本<br />
今天没事干,就发上来<br />
<br />
<br />
#it will copy a new file to another disk like the base dir<br />
#dir path store the file which we want to deal<br />
#要处理的文件夹的结构,注意,并不包括盘符<br />
BASE_DIR = ":/Workspace/IngeniumV512/TS.ROOT/UI/tpl"<br />
#the disk old file store<br />
#IE. here the path is BASE_DIR + BASE_DISK<br />
#要处理的文件夹放在C盘<br />
BASE_DISK = "C"<br />
#the disk new file store<br />
#IE.here the new file will store in NEW_DISK + BASE_DIR<br />
#修改后的文件放在E盘<br />
NEW_DISK&nbsp; = "E"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br />
#define the&nbsp; old value need to replace&nbsp;&nbsp; <br />
#要替换的字符串 &nbsp;&nbsp; <br />
SEARCH_REG = 'FldType="15"' <br />
#define the new value to replace the old value<br />
#新的字符串<br />
REPLACE_REG = 'FldType="8"' <br />
#要处理的文件类型<br />
FILE_TYPE = "xml"<br />
<br />
def all_over_dir(dir) <br />
&nbsp;<br />
&nbsp;<br />
&nbsp;Dir.foreach&nbsp; "#{BASE_DISK}#{dir}" do |item|<br />
&nbsp;&nbsp; #判断是否文件<br />
&nbsp;&nbsp; if File.file?("#{BASE_DISK}#{dir}/#{item}")<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #判断是否需要处理的文件类型<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if /"*.#{FILE_TYPE}/ =~ item<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str = ''<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; need_to_replace = false<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; begin&nbsp;&nbsp;&nbsp; <br />
<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;f = File.open("#{BASE_DISK}#{dir}/#{item}")<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;f.each do |line|<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if line.include? SEARCH_REG<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; line.sub! SEARCH_REG , REPLACE_REG<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; need_to_replace = true<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; str &lt;&lt; line<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; #如果查找到要替换的字符,则处理该文件<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if need_to_replace<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; make_dir "#{NEW_DISK}#{dir}"<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; file = File.new "#{NEW_DISK}#{dir}/#{item}","w"<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp; file.write str<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;end<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; rescue =&gt; err<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; puts err<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; end<br />
&nbsp;&nbsp;&nbsp; &nbsp; end<br />
&nbsp;&nbsp; elsif (item != '..' and item != '.')<br />
&nbsp;&nbsp;&nbsp;&nbsp; #如果是文件夹,则递归处理<br />
&nbsp;&nbsp;&nbsp;&nbsp; all_over_dir "#{dir}/#{item}"<br />
&nbsp;&nbsp; end<br />
&nbsp;end<br />
end<br />
#该方法作用是创建目录,因为我把替换了的文件是拷到别一个盘,同样结构的文件夹中的<br />
def make_dir(path)<br />
&nbsp;&nbsp; p = ''<br />
&nbsp;&nbsp; array&nbsp; = path.split '/'<br />
&nbsp;&nbsp; p = "#{array[0]}"<br />
&nbsp;&nbsp; i = 1<br />
&nbsp;&nbsp; while i &lt; array.size<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; p &lt;&lt; "/#{array[i]}"<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; begin<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Dir.new p<br />
&nbsp;&nbsp;&nbsp; &nbsp; rescue<br />
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp; Dir.mkdir p<br />
&nbsp;&nbsp;&nbsp; &nbsp; end<br />
&nbsp;&nbsp;&nbsp; &nbsp; i += 1<br />
&nbsp;&nbsp; end&nbsp;&nbsp; <br />
end<br />
<br />
all_over_dir BASE_DIR<br />
<br />
<br />
<br />
<br />
<br />
<img src ="http://www.blogjava.net/sxwailyc/aggbug/220817.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/sxwailyc/" target="_blank">大头@</a> 2008-08-08 09:02 <a href="http://www.blogjava.net/sxwailyc/articles/220817.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>