title: Recursively moving files from one directory to another only partially completes
body: <p>Based on an answer to: <a href="https://stackoverflow.com/questions/2534632/list-all-files-from-a-directory-recursively-with-java">List all files from a directory recursively with Java</a> </p>
  
  <p>I have written a little Filemover which will recursively move every file from a directory and place them in the top level of another directory. But for some reason, the code doesn't move all the files. I switched to using Files.move() but while definitely worth while the code is still not walking the directory tree properly. Now I am getting a <strong>java.nio.file.NoSuchFileException</strong> while trying to move the files.</p>
  
  <p>The stack trace says that its an unknown source, yet when I look to see if the file is there it is. I have isolated the problem to <strong>Files.move()</strong> but I can't seems to fix it. I have tried both <strong>getPath()</strong> and <strong>getAbsolutePath()</strong>. What's even weirder I use a similar method in my sorting routine and it works fine. The only difference is that my source directory has no subdirectories.</p>
  
  <p>I have solved the partial tree walk. It was caused because my ImageFilter only had lower case extensions and the filter needed to be case sensitive. So I fixed it here.</p>
  
  <p>Okay, I switched my little Filemover back to <strong>file.renameTo()</strong> and it works properly now. It's just a testing tool for randomly moving files into a drop directory for my image sorter so it's not worth figuring out why I was getting <strong>no such file exceptions</strong>. I was just modifying it to work recursively so it could be used to reverse a sort if someone used the wrong sorting routine on a bunch of images.</p>
  
  <p>Thanks for all your help :)</p>
  
  <p>I have 3 classes</p>
  
  <pre><code> import java.io.File;
  import java.util.Collection;
  import org.apache.commons.io.FileUtils;
  
  
  
  import org.apache.commons.io.FileUtils;
  import org.apache.commons.io.filefilter.DirectoryFileFilter;
  
  import ca.fotonow.p3software.ImageFileFilter;
  
  public class PSFileUtils {
      public static Collection&lt;File&gt; listfiles(String directory) {
  
          // TODO Auto-generated method stub
          File dir= new File (directory);
          dir.mkdirs(); //create directory if it doesn't exist.
          Collection&lt;File&gt; files= FileUtils.listFiles(dir,new ImageFileFilter(),DirectoryFileFilter.DIRECTORY);
  
  
          return files;
      }
     }
  </code></pre>
  
  <p>Filter Class</p>
  
  <pre><code>import java.io.File;
  import java.io.FileFilter;
  
  import org.apache.commons.io.filefilter.IOFileFilter;
  
  public class ImageFileFilter implements IOFileFilter {
      private final String filetypes[]= new String[] {"jpeg", "JPEG","jpg","JPG","tif","TIF","tiff","TIFF","raw","RAW"}; 
      @Override
      public boolean accept(File file) {
          for (String ext: filetypes) {
              if (file.getName().toLowerCase().endsWith(ext)) return true;
          }
          return false;
      }
      @Override
      public boolean accept(File arg0, String arg1) {
          // TODO Auto-generated method stub
          return false;
      }
  
  }
  </code></pre>
  
  <p>The main class</p>
  
  <pre><code>import java.io.File;
  import java.util.Collection;
  import java.util.Date;
  import java.util.Random;
  import java.nio.file.Files;
  import static java.nio.file.StandardCopyOption.*;
  
  public class FileMover {
  
      /**
       * @param args
       */
      public static void main(String[] args) {
      //Move random number of files from one directory args[0] to another directory args[1]
      //directories can be relative
      //Repeats randomly until files are gone
  
      String dir1=args[0];
      String dir2=args[1];
  
  
  
      Collection&lt;File&gt; files=PSFileUtils.listfiles(dir1);
  
      for (File file: files) {
  
          File newfile=new File(dir2+"/"+file.getName());
  
          try {
          Files.move(file.toPath(),newfile.toPath(), REPLACE_EXISTING);
      } catch (IOException e1) {
          // TODO Auto-generated catch block
          e1.printStackTrace();
      }
          System.out.println((new Date()).getTime()+ " "+ newfile.getName());
  
          Random generator =new Random(new Date().getTime());
          try {
              Thread.sleep(generator.nextInt(5000));
          } catch (InterruptedException e) {
              // TODO Auto-generated catch block
              e.printStackTrace();
          }
      }
  }
  
  }
  </code></pre>
  
  <p>Any idea of what I have wrong?</p>