ERMsg CDirectoryManager::CopyFile(const std::string& oldFileName, const std::string& newFileName)const
	{
		ASSERT(oldFileName != newFileName);

		ERMsg msg;
		bool bHaveExt = !GetFileExtension(oldFileName).empty();

		string oldFilePath = GetFilePath(oldFileName);
		string newFilePath(oldFilePath);
		if (bHaveExt)
			SetFileName(newFilePath, newFileName);
		else
			SetFileTitle(newFilePath, newFileName);

		msg = CopyOneFile(oldFilePath, newFilePath);

		/*
		bool bChangeExt = GetFileExtension(fileName).empty();


		std::string filePath = GetFilePath(fileName);
		ASSERT( !filePath.empty() );
		TRY
		{
		std::string strSrh = filePath;
		if( bChangeExt )
		UtilWin::SetFileExtension(strSrh, ".*");

		StringVector filePathList;
		UtilWin::GetFilesList(filePathList, strSrh, true);
		for(int i=0; i<filePathListsize(); i++)
		{
		std::string newFilePath = filePathList[i];
		if( bChangeExt )
		UtilWin::SetFileTitle(newFilePath, newFileName);
		else UtilWin::SetFileName(newFilePath, newFileName);

		if( !::CopyFile(filePathList[i], newFilePath, true) )
		{
		msg = SYGetMessage( GetLastError() );
		std::string erreur;
		erreur.FormatMsg(IDS_CMN_UNABLE_COPY_FILE, (LPCTSTR)filePathList[i]);
		msg.ajoute(erreur);
		}
		}
		}
		CATCH(CFileException, e)
		{
		msg = SYGetMessage(*e);
		}
		END_CATCH
		*/
		return msg;
	}
Exemple #2
0
void CSetupApp::CopyWinDirStatFiles(CProgressDlg *progress)
{
	CStringArray files;
	progress->SetTotal(GetFilesToCopy(files));

	for (int i=0; i < files.GetSize(); i++)
	{
		CString dest= m_destFolder + _T("\\") + GetBaseNameFromPath(files[i]);
		// CopyFileEx is not available on Windows 95.
		// So we must do it ourselves.
		CopyOneFile(files[i], dest, progress);
	}
}
/*
 * recursiveCp - copy a file to a directory (recursively entered)
 *
 * source_head  points to a buffer of size _MAX_PATH that ends with a ':'
 *              or a FILESEP.
 * source_tail  points to the null terminator of source_head.
 * source_wild  is the filename/pattern to append to source_head to get the
 *              names of the file(s) to copy.
 * dest_head    points to a buffer of size _MAX_PATH that ends with a ':'
 *              or a FILESEP
 * dest_tail    points to the null terminator of dest_head.
 *
 * Note that the buffers source_head/dest_head are passed down the
 * recursion to save stack space.
 */
static void recursiveCp( char *source_head, char *source_tail,
    char *source_wild, char *dest_head, char *dest_tail )
{

    DIR                 *directory;
    struct dirent       *nextdirentry;
    void                *crx = NULL;
    char                *new_source_tail;
    char                *new_dest_tail;

    pathCopy( source_head, source_tail, "*.*" );

    directory = opendir( source_head );
    if( directory == NULL ) {
        DropPrintALine( "file \"%s\" not found", source_head );
        return;
    }

    if( rxflag ) {
        char *err = FileMatchInit( &crx, source_wild );
        if( err != NULL ) {
            Die( "\"%s\": %s\n", err, source_wild );
        }
    }

    /*
     * loop through all files
     */
    while( ( nextdirentry = readdir( directory ) ) != NULL ) {
        /*
         * set up file name, then try to copy it
         */
        FNameLower( nextdirentry->d_name );
        if( rxflag ) {
            if( !FileMatch( crx, nextdirentry->d_name ) ) {
                continue;
            }
        } else {
            if( !FileMatchNoRx( nextdirentry->d_name, source_wild ) ) {
                continue;
            }
        }
        new_source_tail = pathCopy( source_head, source_tail,
            nextdirentry->d_name );
        new_dest_tail = pathCopy( dest_head, dest_tail, nextdirentry->d_name );

        if( nextdirentry->d_attr & _A_SUBDIR ) {

            if( !IsDotOrDotDot( nextdirentry->d_name ) && rflag ) {
                int     rc;

                rc = mkdir( dest_head );
                if( !rc ) {
                    DirCnt++;
                }
                if( !sflag ) {
                    if( rc ) {
                        PrintALineThenDrop( "directory %s already exists",
                            dest_head );
                    } else {
                        PrintALineThenDrop( "created new directory %s",
                            dest_head );
                    }
                }
                new_dest_tail = pathCopy( dest_head, new_dest_tail,
                    FILESEPSTR );
                new_source_tail = pathCopy( source_head, new_source_tail,
                    FILESEPSTR );
                recursiveCp( source_head, new_source_tail,
                    rxflag ? "*" : "*.*",
                    dest_head, new_dest_tail );
            }

        } else {

            CopyOneFile( dest_head, source_head );

        }

    }
    closedir( directory );
    if( rxflag ) {
        FileMatchFini( crx );
    }

} /* DoCP */