0

I move files via apache.commons.io, files were sorted in the array "moveList". When the files are sorted e. g. a.txt, b.txt, c.txt.... y.txt, z.txt, they are not moved in this given order. I think windows does the moving process, what means the first file that is moved is not a.txt, it is some file in the middle like n.txt.

Do you know a solution to start the moving process in the order I want it? Copying files is ok, moving files not.

    for ( Object o : moveList ) {
        Path p = Paths.get(o.toString());

        String replaceFilePath  = o.toString().replace(movePath.toString(), getTargetPath.toString());     // Tauscht getTargetPath mit movePath     
        File newTargetFile      = Paths.get(replaceFilePath).toFile();                                     

        if (newTargetFile.exists() == false){     
            System.out.println("MOVE : " + p+"    to    "+newTargetFile);
            FileUtils.moveFile(p.toFile(), newTargetFile);       
        }else{}   
    }   
  • [`FileUtils.moveFile`](http://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/FileUtils.html#line.2907) appears to behave synchronously. Either I read that source wrong (which is highly possible), or your `moveList` isn't being sorted correctly. – allonhadaya Feb 02 '14 at 16:24
  • Hi, when I print the sorted array list "moveList", it's sorting is different than the moved order. –  Feb 02 '14 at 20:08

1 Answers1

0

If copying is working, you can always use "copy" and "delete". Although this approach is not the best one, it could be enough for your problem...

Or maybe these will help you... http://www.mkyong.com/java/how-to-move-file-to-another-directory-in-java/ Move / Copy File Operations in Java

Community
  • 1
  • 1
arenaq
  • 2,304
  • 2
  • 24
  • 31
  • that's happening under the scenes anyways: http://commons.apache.org/proper/commons-io/apidocs/src-html/org/apache/commons/io/FileUtils.html#line.2928 – allonhadaya Feb 02 '14 at 16:13
  • exactly... then it doesn't matter and he can implement it by himself – arenaq Feb 02 '14 at 16:46
  • Thanks, I implemented copying first, but I i wanted real moving, too, because it is faster –  Feb 02 '14 at 20:53