为什么这段代码在 Windows 上失效了?

发布于 2024-10-04 11:42:30 字数 965 浏览 0 评论 0原文

我正在尝试将一些代码从 Linux 移植到 Windows。我对 Windows 真的不太了解,所以我有点盲目。有问题的代码尝试使用 org.apache.commons.io.FileUtils 删除某些目录

  // If the mergesegs worked, delete the segment dirs
    for (File file : segments.listFiles())
    {
        if (!file.equals(mergedSegFile))
        {
            LOG.debug("deleting segment dir " + file);
            FileUtils.deleteDirectory(file);
        }
    }

segments 是一个文件,mergedSegFile 也是一个文件。它因 IOException “无法删除文件:c:\www\tomcat\crawls\test\TestingCode.site\crawldir\segments\20101128194700\parse_test\part-00000\data”而终止。

这些文件是由先前运行的同一程序(执行一些 Nutch 爬行)创建的。在 cygwin 下执行 ls -l 显示用户和组是正确的,但权限为 000。

更多信息:

  • dir 没有告诉我任何有关权限的信息。
  • 我可以在 cmd.exe 窗口上使用 del 或在 cygwin bash 窗口上使用 rm -rf 删除目录。
  • 有问题的文件及其所在的目录是在同一程序的同一次运行中早期创建的。
  • 计算机运行的是 Windows 7,所以我认为这意味着它是 NTFS。

I'm trying to port some code from Linux to Windows. I really don't know much about Windows, and so I'm kind of flying blind. The code in question attempts to delete some directories using org.apache.commons.io.FileUtils

  // If the mergesegs worked, delete the segment dirs
    for (File file : segments.listFiles())
    {
        if (!file.equals(mergedSegFile))
        {
            LOG.debug("deleting segment dir " + file);
            FileUtils.deleteDirectory(file);
        }
    }

segments is a File, as is mergedSegFile. It dies with an IOException "Unable to delete file: c:\www\tomcat\crawls\test\TestingCode.site\crawldir\segments\20101128194700\parse_test\part-00000\data".

These files were created by a previous run of the same program (which does some Nutch crawling). Doing an ls -l under cygwin shows the user and group are correct, but the perms are 000.

Further info:

  • dir doesn't tell me anything about permissions.
  • I can remove the directory with del on a cmd.exe window or rm -rf on a cygwin bash window.
  • The files in question, and the directory they are in, were created earlier in the same run of the same program.
  • The computer is running Windows 7, so I assume that means it's NTFS.

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

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

发布评论

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

评论(1

苹果你个爱泡泡 2024-10-11 11:42:30

这里有很多可能性。这条路本身看起来并不糟糕。最好的办法是尝试从命令提示符手动删除该目录,然后查看出现的错误。

要检查的事项:

  • 该目录或其任何内容是否正在被应用程序使用?
  • 该目录或其任何文件是只读的吗? (检查dir,而不是ls)。
  • 该目录或其任何文件是否具有特殊权限,并且您不是管理员?
  • 顺便说一句,我猜这是 NTFS?

Plenty of possibilities here. The path itself doesn't look bad. Your best bet is to try to delete that directory manually from a command prompt and see what error you get.

Things to check:

  • Is the directory, or any of its contents, in use by an application?
  • Is the directory, or any of its files, read-only? (Check with dir, not ls).
  • Does the directory, or any of its files, have special permissions, and you are not an administrator?
  • Btw, this is NTFS, I presume?
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文