This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates 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 OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Move a directory?" Watch "Move a directory?" New topic
Author

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?

THANKS
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.

Petr


Get a better web browser:<br /><a href="http://www.mozilla.org/products/firefox/switch.html" target="_blank" rel="nofollow">http://www.mozilla.org/products/firefox/switch.html</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
- ...

P.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Move a directory?