is_dir.h 710 B

12345678910111213141516171819202122232425262728
  1. namespace igl
  2. {
  3. // Act like php's is_dir function
  4. // http://php.net/manual/en/function.is-dir.php
  5. // Tells whether the given filename is a directory.
  6. // Input:
  7. // filename Path to the file. If filename is a relative filename, it will
  8. // be checked relative to the current working directory.
  9. // Returns TRUE if the filename exists and is a directory, FALSE
  10. // otherwise.
  11. bool is_dir(const char * filename);
  12. }
  13. // Implementation
  14. #include <sys/stat.h>
  15. bool igl::is_dir(const char * filename)
  16. {
  17. struct stat status;
  18. if(stat(filename,&status)!=0)
  19. {
  20. // path does not exist
  21. return false;
  22. }
  23. // Tests whether existing path is a directory
  24. return S_ISDIR(status.st_mode);
  25. }