[OT, unix] Looking for recursive soft linking incantation
Avi Bryant
avi at beta4.com
Fri Feb 8 20:24:28 UTC 2002
On Fri, 8 Feb 2002, Tim Rowledge wrote:
> For all you unix gurus out there -
> I'd like to be able to have a simple script that will run through the
> VMMaker platforms tree and make a parallel tree with links between the
> two; the tricky extra is that I need to apply a trivial transform to the
> filenames.
>
> i.e. /foo/bar/one.[c,h] needs to become /foo/bar/[c,h]/one
This seems to do it, although you probably wanted something with a more
widespread interpreter:
#!/usr/local/bin/ruby
require 'find'
src = File.expand_path(ARGV[0])
dest = File.expand_path(ARGV[1])
Find.find(src) do |srcfile|
destfile = srcfile.sub(src, dest)
if FileTest.directory?(srcfile)
Dir.mkdir(destfile) unless FileTest.exists?(destfile)
elsif File.basename(srcfile) =~ /(.*)[.]([hc])/
dir = File.dirname(destfile) + '/' + $2
Dir.mkdir(dir) unless FileTest.exists?(dir)
File.symlink(srcfile, dir + '/' + $1)
else
File.symlink(srcfile, destfile)
end
end
More information about the Squeak-dev
mailing list
|