The POSIX solution is stat()
:
These functions return information about a file.
Basically, you hand it an instance of the struct stat
, and if the call succeeds (check this first!) you get various fields filled in that describe the file.
You can then use the S_ISDIR()
macro on the st_mode
field to figure out if it's a directory. I suspect this is what Python does, under the hood.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.