我试图在 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/