# symlinkDirectory(String,String) -- make symbolic links for all files in a directory tree

## Synopsis

• Usage:
• Inputs:
• src, , the path to an existing directory, the root of the source directory tree
• dst, , a path to the root of the destination directory tree, which may not exist yet
• Optional inputs:
• Exclude => ..., default value \.~[0-9.]+~\$, a string containing a regular expression, or a list of such strings. If the base part of the name of a file in the source tree matches one of the regular expressions, then no link to it is created
• Undo => , default value false, whether to undo the symbolic links created in a previous application of this function. The directories in the destination directory tree will remain.
• FollowLinks => , default value false, whether to follow symbolic links in the source tree to directories
• Verbose => , default value false, whether to report the creation or deletion of each symbolic link
• Consequences:
• The directory tree rooted at src is duplicated by a directory tree rooted at dst. The files in the source tree are represented by relative symbolic links in the destination tree to the original files in the source tree.

## Description

 i1 : src = temporaryFileName() | "/" o1 = /tmp/M2-247714-0/0/ i2 : dst = temporaryFileName() | "/" o2 = /tmp/M2-247714-0/1/ i3 : makeDirectory (src|"a/") i4 : makeDirectory (src|"b/") i5 : makeDirectory (src|"b/c/") i6 : src|"a/f" << "hi there" << close o6 = /tmp/M2-247714-0/0/a/f o6 : File i7 : src|"a/g" << "hi there" << close o7 = /tmp/M2-247714-0/0/a/g o7 : File i8 : src|"b/c/g" << "ho there" << close o8 = /tmp/M2-247714-0/0/b/c/g o8 : File i9 : symlinkDirectory(src,dst,Verbose=>true) --symlinking: ../../0/a/f -> /tmp/M2-247714-0/1/a/f --symlinking: ../../0/a/g -> /tmp/M2-247714-0/1/a/g --symlinking: ../../../0/b/c/g -> /tmp/M2-247714-0/1/b/c/g i10 : get (dst|"b/c/g") o10 = ho there i11 : symlinkDirectory(src,dst,Verbose=>true,Undo=>true) --unsymlinking: ../../0/a/f -> /tmp/M2-247714-0/1/a/f --unsymlinking: ../../0/a/g -> /tmp/M2-247714-0/1/a/g --unsymlinking: ../../../0/b/c/g -> /tmp/M2-247714-0/1/b/c/g
Now we remove the files and directories we created.
 i12 : rm = d -> if isDirectory d then removeDirectory d else removeFile d o12 = rm o12 : FunctionClosure i13 : scan(reverse findFiles src, rm) i14 : scan(reverse findFiles dst, rm)