windows - 在haskell中删除文件

标签 windows haskell

我试图在 winhugs 中借助removeFile函数删除haskell中的文本文件。但它给出了一个错误

Program error: price.txt: Directory.removeFile: permission denied

可能是什么原因?

最佳答案

根据 removeFile 的 Hackage 文档,操作可能会失败:

isPermissionError / PermissionDenied The process has insufficient privileges to perform the operation. [EROFS, EACCES, EPERM]

此外,根据 source code在那里,removeFile 只是 Win32 API 中 deleteFile 的一个薄包装:

removeFile :: FilePath -> IO ()
removeFile path =
#if mingw32_HOST_OS
  Win32.deleteFile path
#else
  Posix.removeLink path
#endif

更新

深入研究 winhugs 的源代码后,似乎 Windows API 函数 unlink 实际上被用来删除 Hugs 中的文件:

primFun(primRemoveFile) { /* remove a file     */
  int rc;
  String s = evalName(IOArg(1));

  if (!s) {
    IOFail(mkIOError(NULL,
             nameIllegal,
             "Directory.removeFile",
             "illegal file name",
             &IOArg(1)));
  }

   rc = unlink(s);

  if (rc != 0)
    throwErrno("Directory.removeFile", TRUE, NO_HANDLE, &IOArg(1));
  IOReturn(nameUnit);
}

无论如何,前面的答案是成立的,因为 Haskell 没有引入任何权限约束。相反,任何权限错误都可能是由于底层操作系统环境(用户帐户、打开的文件、权限等)造成的。

关于windows - 在haskell中删除文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20051169/

相关文章:

windows - Writeln 是否能够支持 Unicode?

list - 通过从模式列表中添加 Ints 在 Haskell 中生成 Ints 列表

windows - 如何确定Windows中进程的内存布局?

c# - Windows.Web.Http.HttpClient 抛出 COMException c#

windows - 同时执行多个批处理文件并监控其进程是否完成

haskell : Integer to Int with int signature

haskell - 富有表现力和可组合的错误类型

windows - windows .BAT错误系统找不到指定的路径

haskell - 多态递归与无限类型错误有何关系?

haskell - 离线安装和运行 haskell 包