next | previous | forward | backward | up | top | index | toc | home
Macaulay2 > The Macaulay2 language > file manipulation > copyDirectory(String,String)

copyDirectory(String,String)

Synopsis

Description

i1 : src = temporaryFileName() | "/"

o1 = /tmp/M2-28869-1/
i2 : dst = temporaryFileName() | "/"

o2 = /tmp/M2-28869-2/
i3 : makeDirectory (src|"a/")
i4 : makeDirectory (src|"b/")
i5 : makeDirectory (src|"b/c/")
i6 : src|"a/f" << "hi there" << close

o6 = /tmp/M2-28869-1/a/f

o6 : File
i7 : src|"a/g" << "hi there" << close

o7 = /tmp/M2-28869-1/a/g

o7 : File
i8 : src|"b/c/g" << "ho there" << close

o8 = /tmp/M2-28869-1/b/c/g

o8 : File
i9 : stack findFiles src

o9 = /tmp/M2-28869-1/
     /tmp/M2-28869-1/a/
     /tmp/M2-28869-1/a/f
     /tmp/M2-28869-1/a/g
     /tmp/M2-28869-1/b/
     /tmp/M2-28869-1/b/c/
     /tmp/M2-28869-1/b/c/g
i10 : copyDirectory(src,dst,Verbose=>true)
--copying: /tmp/M2-28869-1/a/f -> /tmp/M2-28869-2/a/f
--copying: /tmp/M2-28869-1/a/g -> /tmp/M2-28869-2/a/g
--copying: /tmp/M2-28869-1/b/c/g -> /tmp/M2-28869-2/b/c/g
i11 : copyDirectory(src,dst,Verbose=>true,UpdateOnly => true)
--skipping: /tmp/M2-28869-1/a/f not newer than /tmp/M2-28869-2/a/f
--skipping: /tmp/M2-28869-1/a/g not newer than /tmp/M2-28869-2/a/g
--skipping: /tmp/M2-28869-1/b/c/g not newer than /tmp/M2-28869-2/b/c/g
i12 : stack findFiles dst

o12 = /tmp/M2-28869-2/
      /tmp/M2-28869-2/a/
      /tmp/M2-28869-2/a/f
      /tmp/M2-28869-2/a/g
      /tmp/M2-28869-2/b/
      /tmp/M2-28869-2/b/c/
      /tmp/M2-28869-2/b/c/g
i13 : get (dst|"b/c/g")

o13 = ho there
Now we remove the files and directories we created.
i14 : rm = d -> if isDirectory d then removeDirectory d else removeFile d

o14 = rm

o14 : FunctionClosure
i15 : scan(reverse findFiles src, rm)
i16 : scan(reverse findFiles dst, rm)

See also