我希望能够确定路径是文件还是目录。我所能得到的只是他们的名字,因为我在c中使用dirent.h并且由于某种原因它不支持entry-> d_type。对于跨平台的linux / windows,我可以检查名称是否包含句点或不查看它是否是文件?
答案 0 :(得分:2)
没有;文件名可以有句点,也可以有目录名称,但都不能。
答案 1 :(得分:1)
对于(struct dirent) - > d_type,它取决于您正在使用的基础文件系统的实现和支持。如果文件系统不支持此功能,则无法使用。
请参阅man
unsigned char d_type
This is the type of the file, possibly unknown. The following constants are defined for its value:
DT_UNKNOWN
The type is unknown. Only some filesystems have full support to return the type of the file, others might always return this value.