home *** CD-ROM | disk | FTP | other *** search
- #include <afxwin.h>
- #pragma hdrstop
- #include "clficrep.hpp"
-
- CFileDirectory::CFileDirectory( int nBlockSize ) : CStringList( nBlockSize )
- {
- }
-
- CFileDirectory::~CFileDirectory()
- {
- }
-
- void CFileDirectory::CreateList( CString rep, CString filter, bool recursive )
- {
- CreateList( rep, filter, 0, recursive );
- }
-
-
- void CFileDirectory::CreateList( CString rep, CString filter, UINT attr, bool recursive )
- {
- WIN32_FIND_DATA FindFileData;
- bool cont = true;
- HANDLE hs;
-
- TRY
- {
- if ( rep.Right(1).Compare("\\") ) rep = rep + "\\";
- }
- CATCH( CMemoryException, ce )
- {
- }
- END_CATCH
- if ( recursive )
- { // On doit d'abord chercher les rΘpertoires
- hs = FindFirstFile( rep + "*.*", &FindFileData );
- while ( hs != INVALID_HANDLE_VALUE && cont )
- {
- if ( stricmp(FindFileData.cFileName,".") && stricmp(FindFileData.cFileName,"..") )
- { // To be sure to don't have the . or .. Dos file
- if ( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
- CreateList( rep + FindFileData.cFileName, filter, attr, recursive );
- }
- cont = FindNextFile(hs,&FindFileData);
- }
- FindClose( hs );
- }
- // ArrivΘ ici, on ne doit plus traiter les rΘpertoires
- cont = true;
- hs = FindFirstFile( rep + filter, &FindFileData );
- while ( hs != INVALID_HANDLE_VALUE && cont )
- {
- if ( !( FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) &&
- (( attr && FindFileData.dwFileAttributes & attr ) || !attr ) )
- AddTail( rep + FindFileData.cFileName );
- cont = FindNextFile(hs,&FindFileData);
- }
- FindClose( hs );
- }
-
-
- int CFileDirectory::FileOperation( CWnd * parent, UINT wFunc, CString destination, long fFlags, int oFlags )
- {
- SHFILEOPSTRUCT ops;
- int bsize = 0;
- CString sbuffer = "";
- POSITION p;
- CString s;
- int rc;
- int i;
- CString rep = destination;
-
- // first, where have to calculate the buffer size
- // We use the CStringList functions
- if ( wFunc != FO_DELETE )
- {
- if ( oFlags & FOO_KEEPTREE ) destination = "";
- p = GetHeadPosition();
- while ( p )
- {
- s = GetNext(p);
- sbuffer = sbuffer + s;
- sbuffer += '\0';
- bsize += s.GetLength();
- if ( oFlags & FOO_KEEPTREE ) // We have to create the dest. file list
- {
- i = s.Find(":");
- if ( i != -1 ) s = s.Mid(i+1);
- destination += rep;
- destination += s;
- destination += '\0';
- }
- }
- if ( !bsize ) return(-1); // Nothing to do
- if ( oFlags & FOO_KEEPTREE ) destination += '\0';
- sbuffer += '\0';
- }
-
- ops.hwnd = parent->m_hWnd;
- ops.wFunc = wFunc;
- ops.pFrom = LPCTSTR(sbuffer);
- ops.pTo = destination;
- ops.fFlags = fFlags;
- ops.hNameMappings = NULL;
- ops.lpszProgressTitle = "Operation en cours";
-
-
- rc = SHFileOperation(&ops);
-
- return( rc );
- }
-
-