Move files in synchronous way

A

Alessandro

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
 
R

Roedy Green

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
 
R

Richard.Williams.20

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top