ホーム » MFC » Copy SrcFolder\*.txt DstFolder

2011年11月
 12345
6789101112
13141516171819
20212223242526
27282930  

カテゴリー

アーカイブ

ブログ統計情報

  • 77,427 アクセス



Copy SrcFolder\*.txt DstFolder

あるフォルダの複数ファイルのコピーと移動.
 Files_Copy_or_Move を直接利用するのではなく,FolderCopyFiles , FolderMoveFiles を利用します.
//*******************************************************************************
// 関数名 :あるフォルダ直下のファイルのコピーと移動
// 作成日 :’11/11/04
//*******************************************************************************
BOOL Files_Copy_or_Move (LPCTSTR src_Name,LPCTSTR dstPath,const BOOL isDelSrc,const BOOL exist)
{
  CString srcPath = src_Name ;
  CString srcName = _T(“*.*”) ;
  if (CString(srcPath).IsEmpty()) { return FALSE ; }
  if (!::FileIsDirectory(src_Name)) {
    srcPath = ::GetFileDir (src_Name) ;
    srcName = ::GetFileName (src_Name) ;
    }
  if (srcPath == dstPath) { return FALSE ; }
  if (::FileIsNothing(srcPath)) { return FALSE ; } // 元のフォルダが存在しない
  if (::FileIsNothing(dstPath)) {
    if (!::CreateFolder(dstPath)) { return FALSE ; }
    }
  {
    CStringArray srcFiles ;
    ::FolderEnumFiles(srcPath,&srcFiles,srcName) ;
    for (int index=0 ; index<srcFiles.GetSize() ; index++) {
      CString srcFPath = srcFiles[index] ;
      CString srcFName = ::GetFileName(srcFPath) ;
      CString newFName = ::FolderAddLastSP(dstPath) + srcFName ;
      if (!::CopyFile(srcFPath,newFName,exist)) {
        continue ;
        }
      if (isDelSrc) { // 元のファイルは削除? (移動の場合?)
        CFile::Remove(srcFPath) ;
        }
      }
    }
  return TRUE ;
  }

inline BOOL FolderCopyFiles (LPCTSTR srcName, LPCTSTR dstPath, const BOOL exist)
{ return Files_Copy_or_Move ( srcName, dstPath, FALSE, exist) ; }
inline BOOL FolderMoveFiles (LPCTSTR srcName, LPCTSTR dstPath, const BOOL exist=FALSE)
{ return Files_Copy_or_Move ( srcName, dstPath, TRUE, exist) ; }

Is this 投稿 useful? Useful Useless 0 of 0 people say this 投稿 is useful.

コメントする

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

%d人のブロガーが「いいね」をつけました。