This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Move a directory? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Move a directory?" Watch "Move a directory?" New topic

Move a directory?

Max Power
Ranch Hand

Joined: May 10, 2004
Posts: 47
hi, i am trying to move a directory from c:\ to d:\. right now i am using this code:

this works fine, as long as i try to move the dir from c:\ to c:\programs or from c:\prgrams to c:\programs\hello. but as soon as i change the partition (c:\ to d:\) success is always false. can you imagine why?

Petr Blahos
Ranch Hand

Joined: Apr 28, 2004
Posts: 131
Hi Andreas,

you can't rely on that. JavaDoc says:

Whether or not this method can move a file from
one filesystem to another is platform-dependent.

That's it. As to your question why: because it is the
documented behaviour of the function. I am affraid you
will have to copy file by file and then at the end
remove the source.


Get a better web browser:<br /><a href="" target="_blank" rel="nofollow"></a>
Max Power
Ranch Hand

Joined: May 10, 2004
Posts: 47
hello, oh i see. but what if i do not have the permission to delete the directory after copying it?

thanks :-)
Petr Blahos
Ranch Hand

Joined: Apr 28, 2004
Posts: 131
The only thing I can tell you is:
It is not trivial to move a directory. Many things can go
wrong and this permission to delete is only one of them.
You can:
- notify user that it was copied but not removed (I think
most file managers would do this)
- delete what you have copied so far
- ask user what to do
- ...

I agree. Here's the link:
subject: Move a directory?
Similar Threads
Moving File From One Directroy to Another
What s wrong in this file program to move a file to directory
delete files in a driectory
File.renameTo() Failing On Solaris
Problem in moving file