【问题标题】:Can the existence of a period be used to differentiate between a directory and file?句号的存在可以用来区分目录和文件吗?
【发布时间】:2014-12-14 03:48:04
【问题描述】:

我希望能够确定路径是文件还是目录。我所能得到的只是他们的名字,因为我在 c 中使用 dirent.h 并且由于某种原因它不支持 entry->d_type。对于跨平台linux / windows,我可以检查名称是否包含句点来查看它是否是文件?

【问题讨论】:

  • 当然,在跨平台性质的情况下,可以检测文件和目录(存在于文件系统上)之间的差异。如果您的代码没有,请修复它。
  • man 3 statman 7 stat.h

标签: linux windows filesystems


【解决方案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.

【讨论】:

    【解决方案2】:

    没有;文件名可以有句点,目录名也可以,但都不是必须的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-04-13
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      • 2012-02-19
      相关资源
      最近更新 更多