2014-10-18 51 views
0

我希望能夠確定路徑是文件還是目錄。我所能得到的是他們的名字,因爲我在c中使用dirent.h,並且由於某種原因它不支持entry-> d_type。對於跨平臺的linux/windows,我可以只檢查名稱是否包含句點或不能查看它是否是文件?可以使用句號的存在區分目錄和文件嗎?

+0

當然有可能檢測文件和目錄(如存在於文件系統),在跨平臺上下的性質之間的差異。如果你的代碼沒有,修復它。 – user2864740 2014-10-18 20:08:53

+0

'man 3 stat'' man 7 stat.h' – Duck 2014-10-18 22:17:37

回答

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

否;文件名可以有句點,也可以有目錄名,但都不是。

相關問題