How to move directory ( with contents) to another directory.

M

mike

I am trying to move a directory ( and it's contents to a new
directory). I have tried the following:

System.out.println(nonCCResource.getLocation().toString());
tmpDir = new File (nonCCResource.getParent().getLocation().toString(),
nonCCResource.getName()+".tmp");
boolean success = tmpDir.mkdirs();
File dir = new
File(nonCCResource.getParent().getLocation().toString(),
nonCCResource.getName());
boolean success1 = dir.renameTo(tmpDir);

When checking success1 it is false. And the success is true.

Any ideas how I can do this.

cheers,

//mike
 
R

Roedy Green

I am trying to move a directory ( and it's contents to a new
directory). I have tried the following:

You can't rename a directory to move it to a different drive. You
must have permissions on it to rename it.

To move it to a different drive, you have to create a new dir, copy
the files over, and then delete the original files and directory.

If you want help from others, simplify your code to use hard coded
strings or at least do println of each of your files so people can
what the net result of your calls is.
 

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

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,832
Latest member
GlennSmall

Latest Threads

Top