gpt4 book ai didi

file - 如何测试FILE在D中是否存在且可读

转载 作者:行者123 更新时间:2023-11-28 20:06:24 24 4
gpt4 key购买 nike

如何判断一个文件在 D 中是否可读?我多次搜索了 google 和 D 的文档和东西——我也搜索了 SO 多次——但我没能找到关于测试给定文件是否可读的任何 .从理论上讲,我知道如何在 C 中使用 __freadable——我什至尝试在 D 中对 __freadable 进行外部调用,但出现以下链接错误:

ldc2  -O2 -dw -g -wi -I/usr/include/stdio_ext.h -c ket.d ket.o
ldc2 -O2 -dw -g -wi -I/usr/include/stdio_ext.h -ofket ket.o
ket.o: In function `_Dmain':
/home/hav3lock/sy.l/repos/pub_rel/ket/ket.d:47: undefined reference to `_D3ket4mainFAAyaZv11__freadableUPOS4core4stdc5stdio6_iobufZi'
collect2: error: ld returned 1 exit status
Error: /usr/bin/gcc failed with status: 1
make: *** [ket] Error 1

我阅读了更多关于在 D 中调用 C 的东西,显然我需要重写 stdio_ext.h C 头文件——__freadable 存在的地方——作为 D 头文件或类似的东西,而且工作量超出了我要做的事情的范围。

我只想确定给定文件是否可读,以便我可以一次性确定该文件是否存在以及它是否也可读。如果我用 bash 写这个傻瓜,我会使用

[[ -r FILE ]] 

测试 FILE 是否存在并授予读取权限,但我无法找到如何在 D 中执行等效操作...有什么想法吗?


尝试使用 getAttributes,但 D 提示:

no property 'getAttributes' for type 'File'

下面是我如何使用 getAttributes

    auto file_a = File(proc_auto[hdex], "r");
writeln(file_a.getAttributes);

最佳答案

当您在 http://www.dlang.org 上有出色的 Phobos 引用时,为什么还要谷歌搜索? ?

你要找的是std.file.getAttributes()功能。

关于file - 如何测试FILE在D中是否存在且可读,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17526256/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com