Exemple #1
0
bool kiFindFile::findfirst( const char* wild, WIN32_FIND_DATA* pfd )
{
	HANDLE xh = ::FindFirstFile( wild, pfd );
	if( xh==INVALID_HANDLE_VALUE )
		return false;
	while( isDots(pfd->cFileName) )
		if( !::FindNextFile( xh, pfd ) )
		{
			::FindClose( xh );
			return false;
		}
	::FindClose( xh );
	return true;
}
Exemple #2
0
bool kiFindFile::begin( const char* wild )
{
	close();

	h = ::FindFirstFile( wild, &fd );
	if( h==INVALID_HANDLE_VALUE )
		return false;
	while( isDots(fd.cFileName) )
		if( !::FindNextFile( h, &fd ) )
		{
			close();
			return false;
		}
	return true;
}
Exemple #3
0
bool kiFindFile::next( WIN32_FIND_DATA* pfd )
{
	if( h==INVALID_HANDLE_VALUE )
		return false;
	if( first )
	{
		first = false;
		ki_memcpy( pfd, &fd, sizeof(fd) );
		return true;
	}
	if( !::FindNextFile( h, pfd ) )
		return false;
	while( isDots(fd.cFileName) )
		if( !::FindNextFile( h, pfd ) )
			return false;
	return true;
}
Exemple #4
0
void WindowsFiles::list(const std::string& path, std::vector< FileHandle>& handles) const
{
	handles.clear();
	if( isDirectory( path))
	{
		WIN32_FIND_DATA FileData; 
		HANDLE hSearch; 

		std::string strSearchText = path;
		strSearchText +=  "\\*";
		

		hSearch = FindFirstFile( strSearchText.c_str(), &FileData); 

		do 
		{
			if(!isDots(FileData.cFileName))
				handles.push_back( FileHandle( path + "/" + FileData.cFileName));
		} 
		while (FindNextFile(hSearch, &FileData));
		FindClose( hSearch);
	}
}
Exemple #5
0
bool WindowsFiles::recursiveDeleteDirectory(const std::string& path) const
{
   HANDLE hFind;
   WIN32_FIND_DATA FindFileData;
 
   TCHAR dirPath[MAX_PATH];
   TCHAR fileName[MAX_PATH];
 
   strcpy(dirPath,path.c_str());
   strcat(dirPath, "\\*");
   strcpy(fileName, path.c_str());
   strcat(fileName,"\\");
 
   // find the first file
   hFind = FindFirstFile(dirPath, &FindFileData);
   if(hFind == INVALID_HANDLE_VALUE) 
	   return false;
   
   strcpy(dirPath, fileName);
 
   bool bSearch = true;
   while(bSearch) 
   {    
	   // until we find an entry
      if(FindNextFile(hFind,&FindFileData)) 
	  {
         if(isDots(FindFileData.cFileName)) 
			 continue;
         strcat(fileName,FindFileData.cFileName);
         if((FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) 
		 {
             // we have found a directory, recurse
            if(!recursiveDeleteDirectory(fileName)) 
			{
                FindClose(hFind);
                return false;    // directory couldn't be deleted
            }
            // remove the empty directory
            RemoveDirectory(fileName);
             strcpy(fileName, dirPath);
         }
		 else
		 {
			 if(!::DeleteFile(fileName))
			 {
				// some error occurred; close the handle and return FALSE
				FindClose(hFind);
				return false;
			 }
		 }
      }
      else 
	  {
         // no more files there
         if(GetLastError() == ERROR_NO_MORE_FILES)
			bSearch = false;
         else 
		 {
            // some error occurred; close the handle and return FALSE
               FindClose(hFind);
               return false;
         }
       }
    }
   FindClose(hFind);                  // close the file handle
   return RemoveDirectory(path.c_str()) == TRUE;     // remove the empty directory
}