瀏覽代碼

*** empty log message ***

David Rose 25 年之前
父節點
當前提交
768fdab67a
共有 2 個文件被更改,包括 57 次插入0 次删除
  1. 55 0
      dtool/src/dtoolutil/filename.cxx
  2. 2 0
      dtool/src/dtoolutil/filename.h

+ 55 - 0
dtool/src/dtoolutil/filename.cxx

@@ -581,6 +581,61 @@ exists() const {
   return exists;
   return exists;
 }
 }
 
 
+////////////////////////////////////////////////////////////////////
+//     Function: Filename::is_regular_file
+//       Access: Public
+//  Description: Returns true if the filename exists and is the
+//               name of a regular file (i.e. not a directory or
+//               device), false otherwise.
+////////////////////////////////////////////////////////////////////
+bool Filename::
+is_regular_file() const {
+#ifdef WIN32_VC
+  struct _stat this_buf;
+  bool isdir = false;
+
+  if (_stat(to_os_specific().c_str(), &this_buf) == 0) {
+    isdir = S_ISREG(this_buf.st_mode);
+  }
+#else  // WIN32_VC
+  struct stat this_buf;
+  bool isdir = false;
+
+  if (stat(to_os_specific().c_str(), &this_buf) == 0) {
+    isdir = S_ISREG(this_buf.st_mode);
+  }
+#endif
+
+  return isdir;
+}
+
+////////////////////////////////////////////////////////////////////
+//     Function: Filename::is_directory
+//       Access: Public
+//  Description: Returns true if the filename exists and is a
+//               directory name, false otherwise.
+////////////////////////////////////////////////////////////////////
+bool Filename::
+is_directory() const {
+#ifdef WIN32_VC
+  struct _stat this_buf;
+  bool isdir = false;
+
+  if (_stat(to_os_specific().c_str(), &this_buf) == 0) {
+    isdir = S_ISDIR(this_buf.st_mode);
+  }
+#else  // WIN32_VC
+  struct stat this_buf;
+  bool isdir = false;
+
+  if (stat(to_os_specific().c_str(), &this_buf) == 0) {
+    isdir = S_ISDIR(this_buf.st_mode);
+  }
+#endif
+
+  return isdir;
+}
+
 ////////////////////////////////////////////////////////////////////
 ////////////////////////////////////////////////////////////////////
 //     Function: Filename::compare_timestamps
 //     Function: Filename::compare_timestamps
 //       Access: Public
 //       Access: Public

+ 2 - 0
dtool/src/dtoolutil/filename.h

@@ -122,6 +122,8 @@ public:
   string to_os_specific() const;
   string to_os_specific() const;
 
 
   bool exists() const;
   bool exists() const;
+  bool is_regular_file() const;
+  bool is_directory() const;
   int compare_timestamps(const Filename &other,
   int compare_timestamps(const Filename &other,
 			 bool this_missing_is_old = true,
 			 bool this_missing_is_old = true,
 			 bool other_missing_is_old = true) const;
 			 bool other_missing_is_old = true) const;