Oracle API says about this method:
" This method may be invoked to move an empty directory.
... When invoked to move a directory that is not empty then the directory is moved if it does not require moving the entries in the directory.
... When moving a directory requires that its entries be moved then this method fails (by throwing an IOException)."
I don't understand what that means at all...
I tried it and my experience was the opposite.
I put three files in a folder (rtf, txt, bmp) and tried to move this folder to another place, with the expectation that it would fail and throw an exception.
Well, it didn't. It was smooth, it moved the directory and all of its content to the target place, without any Exception.
Files.move() method and moving directories
Resolved
Comments (4)
- Popular
- New
- Old
You must be signed in to leave a comment
Lisa
29 January 2022, 12:15solution
That means, if it is possible for the OS and the storages filesystem to just move (on linux that means just a rename) the directory, then the move operation is possible. If it is necessary for the OS to move the directories contents, then it fails (exception). Means, if you eg. move the directory to another hd, then of course the files will have to be copied over and the operation will fail. Different partitions on the same drive should work, though. If you have a fat drive, you could try to test that. I'd like to know if that works. But I think even that one just moves the directory entry.
+2
Gellert Varga
29 January 2022, 20:53
1) Ah, enlightenment.:)
So, the fact that move() can be invoked on an empty directory was specifically highlighted in the API because physical moving (e.g. to another drive) only works in case of a directory if it is empty.
But if no physical move is required, then we can move also a non-empty directory with the move() method.
I think I'm starting to understand... Thanks!:)
2) Yes, I have a FAT pendrive, and I tried it on that: It WORKS WELL to move a non-empty directory from one folder to another folder on that FAT pendrive.
3) FAT, NTFS - which one is good or not good? What is the significance?
+1
Gellert Varga
29 January 2022, 21:33
More precisely: FAT32 was that pendrive.
0
Lisa
29 January 2022, 22:26useful
Ahh, OK, thanks for testing. And if you can chose then I think you won't use the ancient FAT or FAT32 file system except it is for a very small drive
https://www.ntfs.com/ntfs_vs_fat.htm
+1