Java renameTo 对包含内容的文件夹

发布于 2024-09-26 02:10:19 字数 286 浏览 3 评论 0原文

只是尝试使用 Java 重命名文件夹树的根目录。

使用 File.renameTo() 仅在 Windows 中有效,文件夹中根本没有内容。我似乎无法确定这是否是预期的行为。文档中似乎没有提到。

我目前必须使用递归文件\文件夹复制过程,然后删除原始文件,但这比我在文件夹树中所希望的要密集得多,其中每个节点可能有数百个子节点。

看起来 Java 7 有 Path.moveTo() 但我还不能使用 7。

我是否坚持以肮脏的方式做这件事,或者有没有办法只更改根文件夹名称?

谢谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

合久必婚 2024-10-03 02:10:19

您绝对可以在 Windows 中重命名包含内容的文件夹。
但是,如果文件夹中的某个文件已打开以进行输出,则可能存在文件锁定,导致您无法重命名父文件夹。

使用来自 sysinternals 的优秀 Process Explorer 查找文件锁。
它就像类固醇的任务管理器。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文