// define the types and functions used for file searching
// ----------------------------------------------------------------------------
+namespace
+{
+
typedef WIN32_FIND_DATA FIND_STRUCT;
typedef HANDLE FIND_DATA;
typedef DWORD FIND_ATTR;
-static inline FIND_DATA InitFindData() { return INVALID_HANDLE_VALUE; }
+inline FIND_DATA InitFindData()
+{
+ return INVALID_HANDLE_VALUE;
+}
-static inline bool IsFindDataOk(FIND_DATA fd)
+inline bool IsFindDataOk(FIND_DATA fd)
{
return fd != INVALID_HANDLE_VALUE;
}
-static inline void FreeFindData(FIND_DATA fd)
+inline void FreeFindData(FIND_DATA fd)
{
- if ( !::FindClose(fd) )
- {
- wxLogLastError(_T("FindClose"));
- }
+ if ( !::FindClose(fd) )
+ {
+ wxLogLastError(_T("FindClose"));
+ }
}
-static inline FIND_DATA FindFirst(const wxString& spec,
- FIND_STRUCT *finddata)
+inline FIND_DATA FindFirst(const wxString& spec,
+ FIND_STRUCT *finddata)
{
- return ::FindFirstFile(spec, finddata);
+ return ::FindFirstFile(spec.fn_str(), finddata);
}
-static inline bool FindNext(FIND_DATA fd, FIND_STRUCT *finddata)
+inline bool FindNext(FIND_DATA fd, FIND_STRUCT *finddata)
{
- return ::FindNextFile(fd, finddata) != 0;
+ return ::FindNextFile(fd, finddata) != 0;
}
-static const wxChar *GetNameFromFindData(FIND_STRUCT *finddata)
+const wxChar *GetNameFromFindData(FIND_STRUCT *finddata)
{
- return finddata->cFileName;
+ return finddata->cFileName;
}
-static const FIND_ATTR GetAttrFromFindData(FIND_STRUCT *finddata)
+inline FIND_ATTR GetAttrFromFindData(FIND_STRUCT *finddata)
{
- return finddata->dwFileAttributes;
+ return finddata->dwFileAttributes;
}
-static inline bool IsDir(FIND_ATTR attr)
+inline bool IsDir(FIND_ATTR attr)
{
- return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
+ return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
}
-static inline bool IsHidden(FIND_ATTR attr)
+inline bool IsHidden(FIND_ATTR attr)
{
- return (attr & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0;
+ return (attr & (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM)) != 0;
}
+} // anonymous namespace
+
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
int m_flags;
- DECLARE_NO_COPY_CLASS(wxDirData)
+ wxDECLARE_NO_COPY_CLASS(wxDirData);
};
// ============================================================================
{
filespec += _T('\\');
}
- filespec += (!m_filespec ? _T("*.*") : m_filespec.c_str());
+ if ( !m_filespec )
+ filespec += _T("*.*");
+ else
+ filespec += m_filespec;
m_finddata = FindFirst(filespec, PTR_TO_FINDDATA);
#ifdef __WIN32__
DWORD err = ::GetLastError();
- if ( err != ERROR_FILE_NOT_FOUND )
+ if ( err != ERROR_FILE_NOT_FOUND && err != ERROR_NO_MORE_FILES )
{
wxLogSysError(err, _("Can not enumerate files in directory '%s'"),
m_dirname.c_str());
bool wxDir::Open(const wxString& dirname)
{
delete M_DIR;
- m_data = new wxDirData(dirname);
+
+ // The Unix code does a similar test
+ if (wxDirExists(dirname))
+ {
+ m_data = new wxDirData(dirname);
- return true;
+ return true;
+ }
+ else
+ {
+ m_data = NULL;
+
+ return false;
+ }
}
bool wxDir::IsOpened() const
wxGetDirectoryTimes(const wxString& dirname,
FILETIME *ftAccess, FILETIME *ftCreate, FILETIME *ftMod)
{
+#ifdef __WXWINCE__
+ // FindFirst() is going to fail
+ wxASSERT_MSG( !dirname.empty(),
+ _T("incorrect directory name format in wxGetDirectoryTimes") );
+#else
// FindFirst() is going to fail
wxASSERT_MSG( !dirname.empty() && dirname.Last() != _T('\\'),
_T("incorrect directory name format in wxGetDirectoryTimes") );
+#endif
FIND_STRUCT fs;
FIND_DATA fd = FindFirst(dirname, &fs);