忍者ブログ
NINJA
[1] [2]
×

[PR]上記の広告は3ヶ月以上新規記事投稿のないブログに表示されています。新しい記事を書く事で広告が消えます。

ファイルをコピーする。

BOOL xxxxxx::CopyAll(LPCTSTR OldFolder, LPCTSTR NewFolder)
{
    CFileFind FileFind;
    CString Str;
    Str.Format( _T("%s\\*.*"), OldFolder );
    FileFind.FindFile( Str, 0 );

    while( FileFind.FindNextFile() != 0 ){
        if( FileFind.IsDots() != 0 ){ continue; }
        CString Name= FileFind.GetFileName();
        CString Dst;
        Dst.Format( _T("%s\\%s"), NewFolder, Name );
        CopyFile( FileFind.GetFilePath(), Dst, FALSE );
    }

    return TRUE;
}

PR
ファイルサイズを取得する。


DWORD xxxxxx::GetFileSize(CString strFileName)
{
    CLASS_MAKE_UTILS;
    DWORD                dwFileSize;
    HANDLE                hFind;
    WIN32_FIND_DATA        file;

    hFind = FindFirstFileW( (LPCWSTR)( strFileName ), &file );

    if( hFind != INVALID_HANDLE_VALUE ){
        dwFileSize = file.nFileSizeHigh * MAXDWORD + file.nFileSizeLow;
        FindClose( hFind );
    } else {
        dwFileSize = -1;
    }

    return dwFileSize / 1024 / 1024 +1;
}

テキストファイルを読込



void xxxxxx::GetTextData(CString strFilePath, CStringArray& strArrTextData)
{
    // パラメータ格納データ
    char            buf[1000];
    CString            strBuf;
    CString            str;

    // ファイル読込み
    CStdioFile fin;
    int                curPos = 0;

    if( !fin.Open( strFilePath, CFile::modeRead | CFile::typeText) ){
        CString error;
        error.Format(_T("Error Read File %s"), strFilePath );
        ::AfxMessageBox(error);
        return;
    }

    CString strW;

    while( fin.ReadString( strW ) ){
        CStringW strBufW = strBuf;
        strArrTextData.Add( strW );
    }
    _wsetlocale(LC_ALL, _T(""));

}

テキストファイルを出力する

BOOL xxxxxx::WriteTextData( CString strFileName, CStringArray& strArrTextData )
{
    CStdioFile    fout;
    CString        str;

    if( !fout.Open( strFileName, CFile::modeCreate | CFile::modeWrite | CFile::typeText ) ){
        ::AfxMessageBox(_T("ファイルの保存に失敗しました。") );
        return FALSE;
    }

    for( int i = 0; i < strArrTextData.GetSize(); i++ ){
        fout.WriteString( strArrTextData.GetAt(i) );
        fout.WriteString( _T("\n") );
    }

    fout.Close();

    return TRUE;
}




ファイル選択ダイアログから、複数のファイルを選択する


BOOL xxxxxx::GetSelectFilePath( CStringArray& strAFilePath )
{

    // http://www.g-ishihara.com/mfc_cd_01.htm

    CString         filter("Img File( *.BMP;*.TIFF )| *.BMP; *.TIFF||");
    CString         filePath, strBuf;
    POSITION        pos = NULL;
    CFileDialog     selDlg(TRUE, NULL, NULL,  OFN_HIDEREADONLY | OFN_ALLOWMULTISELECT | OFN_NOCHANGEDIR, filter);

    int err = 0;
   
    // ファイル名リスト用メモリ確保
    if (!err)
    {
        try
        {
            selDlg.GetOFN().lpstrFile = strBuf.GetBuffer(MAX_PATH *100);
            selDlg.GetOFN().nMaxFile = MAX_PATH *100;
        }
        catch (...) {err = 1;}
    }
    if( selDlg.DoModal() != IDOK ){
        err = 1;
        return FALSE;
    }

    if ((pos = selDlg.GetStartPosition()) == NULL){
        err = 1;
    }

    if (!err){
        while (pos)
        {
            filePath = selDlg.GetNextPathName(pos);
            strAFilePath.Add( filePath );
        }
    }
    strBuf.ReleaseBuffer();
   
    return TRUE;
}


カレンダー
04 2025/05 06
S M T W T F S
1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
フリーエリア
最新CM
最新TB
プロフィール
HN:
No Name Ninja
性別:
非公開
バーコード
ブログ内検索
アーカイブ
P R
Powered by ニンジャブログ  Designed by ゆきぱんだ
Copyright (c) Visual Studio C++のお勉強 All Rights Reserved
忍者ブログ / [PR]