views:

25

answers:

1

Just trying to use Java to rename the root of a folder tree.

Using File.renameTo() works in Windows only is the folder has no contents at all. I can't seem to find if this is expected behaviour or not. It doesn't seem to be mentioned in the docs.

I am current having to use a recursive file\folder copy process then delete the original, but this is rather more intensive than I was hoping for in a folder tree where each node con potentially have hundreds of children.

It looks like Java 7 has Path.moveTo() but I can't use 7 just yet.

Am I stuck doing it the dirty way, or is there a way to get just the root folder name changed?

Thanks.

+3  A: 

You can definitely rename folders with contents in windows.
However if one of the files in the folder is open for output, then there may be a file lock preventing you from renaming the parent folder.

Find your file locks with the excellent Process Explorer, from sysinternals.
Its like task manager on steroids.

crowne
I had tested for open files before and found none, but I must have missed something I usually do since this time I found one, and I had missed closing a buffer in one place in my code.Thanks for making me recheck the obvious!!
Tim Jones
+1 for process explorer. should be standard on all windows boxes
seanizer