#include #include #include #include using sword::SWBuf; DIR* opendir(const char *pSpec) { DIR *pDir = new DIR; memset(pDir, 0, sizeof(DIR)); pDir->dirPath = new SWBuf(); TCHAR buf[MAX_PATH]; mbstowcs(buf, pDir->dirPath->c_str(), MAX_PATH); *(pDir->dirPath) = adaptpath(pSpec); *(pDir->dirPath) += "\\*"; pDir->hFind = FindFirstFile(buf, &(pDir->wfd)); return pDir; } void closedir(DIR * pDir) { if(pDir->hFind) FindClose( pDir->hFind ); delete pDir->dirPath; delete pDir; } struct dirent* readdir(DIR *pDir) { char buf[MAX_PATH + 1]; if (pDir->hFind) { wcstombs(buf, pDir->wfd.cFileName, MAX_PATH); strcpy(pDir->de.d_name, buf); if ( !FindNextFile(pDir->hFind, &(pDir->wfd)) ){ FindClose(pDir->hFind); pDir->hFind = NULL; } return &pDir->de; } return NULL; } void rewinddir(DIR* dir) { wchar_t buf[MAX_PATH]; if(dir->hFind) FindClose(dir->hFind); mbstowcs(buf, dir->dirPath->c_str(), MAX_PATH); dir->hFind = FindFirstFile(buf, &(dir->wfd)); }