title: Jenkins pipeline script to copy or move file to another destination
body: <p>I am preparing a Jenkins pipeline script in Groovy language. I would like to move all files and folders to another location. As Groovy supports Java so I used below java code to perform the operation.</p>
  
  <p>pipeline{
       agent any    </p>
  
  <pre><code> stages{    
       stage('Organise Files'){                         
           steps{  
                  script{                        
                      File sourceFolder = new File("C:\\My-Source");
                      File  destinationFolder = new File("C:\\My-Destination");                                                   
                      File[] listOfFiles = sourceFolder.listFiles();
                      echo "Files Total: " + listOfFiles.length;  
  
                      for (File file : listOfFiles) {
                          if (file.isFile()) {
                              echo file.getName()                                                                
                              Files.copy(Paths.get(file.path), Paths.get("C:\\My-Destination"));                                   
                          }
                      }                  
                  }                                
              }                           
          } 
      }
  }
  </code></pre>
  
  <p>This code throws the bellow exception: </p>
  
  <blockquote>
    <p>groovy.lang.MissingPropertyException: No such property: Files for
    class: WorkflowScript</p>
  </blockquote>
  
  <p>I tried with below code too, but it's not working either.</p>
  
  <pre><code>FileUtils.copyFile(file.path, "C:\\My-Destination");
  </code></pre>
  
  <p>Finally, I did try with java I/O Stream to perform the operation and the code is bellow:</p>
  
  <pre><code>def srcStream = new File("C:\\My-Source\\**\\*").newDataInputStream()
  def dstStream = new File("C:\\My-Destination").newDataOutputStream()
  dstStream &lt;&lt; srcStream
  srcStream.close()
  dstStream.close()
  </code></pre>
  
  <p>But it's not working either and throws the below exception:</p>
  
  <blockquote>
    <p>java.io.FileNotFoundException: C:\My-Source (Access is denied)</p>
  </blockquote>
  
  <p>Can anyone suggest me how to solve the problem and please also let me know how can I delete the files from the source location after copy or move it? One more thing, during the copy can I filter some folder and files using wildcard? Please also let me know that.</p>