From: "H.Yamamoto" Date: 2004-04-27T19:19:22+09:00 Subject: [ruby-dev:23444] Re: Dir#glob proposal 山本です。 nobu.nakada@nifty.ne.jp wrote: (2004/02/20 12:35) >> |思い付きですが、Dir#globというメソッドはどうでしょうか。例えば、 >> |Dir.open(dir).glob("**/*.rb") とすると dir/**/*.rb が、dirから >> |の相対パスで返されるようなイメージです。 >> >> * どういう風に使うものでしょう > >例えばcp_rとか二つのディレクトリに対して再帰処理をするような場 >合、かなり楽になります。 > > def lndir(src, dest) > parent = src == File.expand_path(src, "/") ? "" : "../" > Dir.open(File.expand_path(src, dest)) do |dir| > dir.glob("**/*") do |file| > if File.directory?(t = File.join(dir.path, file)) > Dir.mkdir(t) > else > File.symlink(parent * file.count("/") + file, File.join(dest, file)) > end > end > end > end > >[ruby-dev:22957]だと、thread safeでないところが。 この提案を考えていたのですが、実は今の Dir.glob も thread safe ではないような気がします。 Dir.glob('foo/**/boo') do |path| Dir.chdir('hoge') end とかすると、基準ディレクトリが処理中に変わってしまいます。これは意図された動作ではないですよね?