Move files in synchronous way

Discussion in 'Java' started by Alessandro, Jun 9, 2009.

  1. Alessandro

    Alessandro Guest

    Hi all,

    I need to move some files (size often more than 1GB) into another
    folder and only at the end of the move (in synchronous way) do other
    actions.

    I have problems to do in synchronous way, with following code it's
    asynchronous:

    //START CODE
    {
    moveFiles(startFold, targetFold);

    //do other actions

    }

    public static void moveFiles(File sourceDir,File targetDir){
    File[] fileList = sourceDir.listFiles();
    for(File sourceFile : fileList)
    sourceFile.renameTo(new File(targetDir,sourceFile.getName()));
    }
    //END CODE



    Do you have any ideas ?
    Thanks and best regards,
    Alessandro
     
    Alessandro, Jun 9, 2009
    #1
    1. Advertising

  2. Alessandro

    Roedy Green Guest

    On Tue, 9 Jun 2009 04:53:04 -0700 (PDT), Alessandro
    <> wrote, quoted or indirectly quoted someone who
    said :

    >I need to move some files (size often more than 1GB) into another
    >folder and only at the end of the move (in synchronous way) do other
    >actions.



    If you do a move, even if the target files already exist, they will be
    replaced. With a rename, you must delete them first.

    What can go wrong?

    1. the only thing that can go wrong is the new name in invalid.

    2. somebody can have the files locked.

    Nothing gets copied unless you are copying from one drive to another.
    Just a new directory entry is created and the old one deleted.

    I am trying to figure out what sort of untoward event you want to
    protect yourself against. I don't see any asynchronous process
    involved.
    --
    Roedy Green Canadian Mind Products
    http://mindprod.com

    Never discourage anyone... who continually makes progress, no matter how slow.
    ~ Plato 428 BC died: 348 BC at age: 80
     
    Roedy Green, Jun 9, 2009
    #2
    1. Advertising

  3. For synchronizing file manipulation activities (move, copy, delete,
    rename, ...), consider using biterscripting ( http://www.biterscripting.com
    ) . It seems to provide a much flexible way of manipulating files.
    Also, for the scripts you write, you can always run them from java as
    the following executable:

    /biterScripting/biterScripting.exe "your script path"


    Richard
     
    Richard.Williams.20, Jul 5, 2009
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. David Hearn
    Replies:
    2
    Views:
    366
    David Hearn
    Aug 9, 2003
  2. no spam
    Replies:
    29
    Views:
    737
    Dave Thompson
    Jan 24, 2005
  3. Rickert
    Replies:
    0
    Views:
    672
    Rickert
    Oct 6, 2011
  4. Eduardo78
    Replies:
    0
    Views:
    258
    Eduardo78
    Nov 3, 2005
  5. Andrew Tomazos
    Replies:
    2
    Views:
    629
    Nobody
    Dec 12, 2011
Loading...

Share This Page