home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 27 / IOPROG_27.ISO / SOFT / CCARACT.ZIP / clficrep.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-30  |  2.8 KB  |  112 lines

  1. #include <afxwin.h>
  2. #pragma hdrstop
  3. #include "clficrep.hpp"
  4.  
  5. CFileDirectory::CFileDirectory( int nBlockSize ) : CStringList( nBlockSize )
  6. {
  7. }
  8.  
  9. CFileDirectory::~CFileDirectory()
  10. {
  11. }
  12.  
  13. void CFileDirectory::CreateList( CString rep, CString filter, bool recursive )
  14. {
  15.  CreateList( rep, filter, 0, recursive );
  16. }
  17.  
  18.  
  19. void CFileDirectory::CreateList( CString rep, CString filter, UINT attr, bool recursive )
  20. {
  21.  WIN32_FIND_DATA FindFileData;
  22.  bool cont = true;
  23.  HANDLE hs;
  24.  
  25.  TRY
  26.  {
  27.  if ( rep.Right(1).Compare("\\") ) rep = rep + "\\";
  28.  }
  29.  CATCH( CMemoryException, ce )
  30.  {
  31.  }
  32.  END_CATCH
  33.  if ( recursive )
  34.  { // On doit d'abord chercher les rΘpertoires
  35.   hs = FindFirstFile( rep + "*.*", &FindFileData );
  36.   while ( hs != INVALID_HANDLE_VALUE && cont )
  37.   {
  38.    if ( stricmp(FindFileData.cFileName,".") && stricmp(FindFileData.cFileName,"..") )
  39.      { // To be sure to don't have the . or .. Dos file
  40.       if ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
  41.         CreateList( rep + FindFileData.cFileName, filter, attr, recursive );
  42.      }   
  43.    cont = FindNextFile(hs,&FindFileData);
  44.   }
  45.   FindClose( hs );
  46.  }
  47.  // ArrivΘ ici, on ne doit plus traiter les rΘpertoires
  48.  cont = true;
  49.  hs = FindFirstFile( rep + filter, &FindFileData );
  50.  while ( hs != INVALID_HANDLE_VALUE && cont )
  51.  {
  52.   if ( !( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
  53.        (( attr && FindFileData.dwFileAttributes & attr ) || !attr ) )
  54.          AddTail( rep + FindFileData.cFileName );
  55.   cont = FindNextFile(hs,&FindFileData);
  56.  }
  57.  FindClose( hs );
  58. }
  59.  
  60.  
  61. int CFileDirectory::FileOperation( CWnd * parent, UINT wFunc, CString destination, long fFlags, int oFlags )
  62. {
  63.  SHFILEOPSTRUCT ops;
  64.  int bsize = 0;
  65.  CString sbuffer = "";
  66.  POSITION p;
  67.  CString s;
  68.  int rc;
  69.  int i;
  70.  CString rep = destination;
  71.  
  72.  // first, where have to calculate the buffer size
  73.  // We use the CStringList functions
  74.  if ( wFunc != FO_DELETE )
  75.    {
  76.     if ( oFlags & FOO_KEEPTREE ) destination = "";
  77.     p = GetHeadPosition();
  78.     while ( p )
  79.      {
  80.       s = GetNext(p);
  81.       sbuffer = sbuffer + s;
  82.       sbuffer += '\0';
  83.       bsize += s.GetLength();
  84.       if ( oFlags & FOO_KEEPTREE ) // We have to create the dest. file list
  85.       {
  86.        i = s.Find(":");
  87.        if ( i != -1 ) s = s.Mid(i+1);
  88.        destination += rep;
  89.        destination += s;
  90.        destination += '\0';
  91.       }
  92.      }
  93.     if ( !bsize ) return(-1); // Nothing to do
  94.     if ( oFlags & FOO_KEEPTREE ) destination += '\0';
  95.     sbuffer += '\0';
  96.    }
  97.  
  98.  ops.hwnd = parent->m_hWnd;
  99.  ops.wFunc = wFunc;
  100.  ops.pFrom = LPCTSTR(sbuffer);
  101.  ops.pTo = destination;
  102.  ops.fFlags = fFlags;
  103.  ops.hNameMappings = NULL;
  104.  ops.lpszProgressTitle = "Operation en cours";
  105.  
  106.  
  107.  rc = SHFileOperation(&ops);
  108.  
  109.  return( rc );
  110. }
  111.  
  112.