| |
// =================================================================
// File Name: filecopy.cpp
// Created by: Xuan Sun
// Date: Jan 2000
// Description: Being able to handle wild charactor file copy command.
//
// =================================================================
#include "stdafx.h"
#include "filecopy.h"
// copy single file, must not have wildchar
// return 0 if successful.
BOOL copy_file(LPCTSTR lpszSource, LPCTSTR lpszDest, BOOL bCopyAttrib)
{
DWORD dwDestAttrib = GetFileAttributes(lpszDest);
DWORD dwSourceAttrib = GetFileAttributes(lpszSource);
BOOL bSuccess = CopyFile(lpszSource, lpszDest, FALSE);// bFailIfExists =FALSE to overwrite
if(bSuccess)
{
if(!bCopyAttrib)
SetFileAttributes(lpszDest, FILE_ATTRIBUTE_NORMAL);
return 0;// no problem, otherwise proceed to find error
}
return (int)GetLastError();
}
// also the no wild card version of copy files.
// copy an individual file when no destination file name is specified.
// Use the name same as the sourse file name
// Return whatever the copy_file function returns.
BOOL copy_file_to_path(LPCTSTR lpszSource, LPCTSTR lpszDestPath, BOOL bCopyAttrib)
{
CString strPath;
CString strPureFileName;
CString strDest;
strDest = lpszDestPath;
(void) GetPathFromFileName(lpszSource, strPath, &strPureFileName);
if(strDest.Right(1) != "\\")
strDest += "\\";
strDest += strPureFileName;
return copy_file(lpszSource, strDest, bCopyAttrib);
}
// return FALSE if error, can immediately call GetLastError()
// lpszSource can contain path and wildchar
BOOL copy_multi_files(LPCTSTR lpszSource, LPCTSTR lpszDestPath, BOOL bCopyAttrib)
{
CStringArray strList;
int fileCount;
CString strPath;
CString strPureFileName;
GetPathFromFileName(lpszSource, strPath, &strPureFileName);
fileCount = GetFileList(lpszSource, strList);
for( int ii=0; ii "is less than" fileCount; ii++) // not able to use less than operator because of HTML
if (copy_file(strPath + strList[ii], lpszDestPath, bCopyAttrib)!=0)
return FALSE;
return TRUE;
}
|
|