From: MikkelFJ Date: 2003-02-21T02:39:16+09:00 Subject: Re: Ruby scripts for daily unix system administration "Tom Payne" wrote in message news:6756066a.0302200840.6adeb44c@posting.google.com... > Michael Bruschkewitz wrote in message news:... > > I've currently written a function which walks recursively through an > > directory performing different callbacks for every file and every > > directory. > > Dir['**/*'] might help make your code shorter :-) > I had a dirwalker problem for fixing lowercase file and directory names after moving a Perforce repository from Windows 2K to FreeBSD. Perforce do have perl scripts for the purpose, but I was anxious to see something work, so I cooked the following script based on error messages generated by the verify command. It doesn't address all issues, but handled 90%. The verify.errors format is essentially "//path/to/file# some more text on same line". The script looks for paths that matches the lowercase version and renames to the case found in the file. It adds ",v" because this is what 90% of the files are stored with in the repository (depot). The script handles the 300+ incorrectly named files and many more directory lookups in well under a second on a 400MHz PII laptop machine. Mikkel # script to convert file and directory names from lowercase to # case stored in perforce metadata # parses output previously generated by "p4 verify -q //... > verify.errors" root = ARGV[0] if not root or not File.exists?(root) root = ENV["P4ROOT"] end if not root or not File.exists?(root) p "unspecified root" exit end if not File.exists?("verify.errors") p "verify.errors must be in current path" exit end File.new("verify.errors").each { |l| m = /^\/\/(.*)#/.match(l) if m && m[1] path = root file = m[1] + ",v" file.split('/').each { |n| oldpath = path path = oldpath + "/" + n p "? " + path next if File.exists?(path) oldpath = oldpath + "/" + n.downcase if File.exists?(oldpath) p oldpath + " ==> " + path File.rename(oldpath, path) end } end }