Copying and Moving Files Using .NET


A couple of little functions to do some grunt-work...

       ⎕vr 'CopyFile'
     ∇ z←CopyFile w;⎕IO;⎕ML;⎕USING;⎕TRAP
      ⍝ Copy a file
      ⎕IO ⎕ML ⎕USING←0 3('System' 'System.IO')
      :Trap 90
          File.Copy w,1
          z←1
      :Else
          z←0
      :EndTrap
     ∇

Example:

      CopyFile 'c:\dick\temp\old.txt' 'c:\dick\temp\new.txt'
1

and...

      ⎕vr 'MoveFile'
     ∇ z←MoveFile(from to);⎕IO;⎕ML;⎕USING;⎕TRAP
       ⍝ Move a file
      ⎕IO ⎕ML ⎕USING←0 3('System' 'System.IO')
      :Trap 90
          File.Move from to
          z←1
      :Else
          z←0
      :EndTrap
    ∇

      MoveFile 'c:\dick\temp\old.txt' 'c:\dick\temp\new.txt'
1

Notes:
Page created 3 March 2009.
Copyright © Dogon Research 2009.