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

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

フォルダを削除する。



BOOL xxxxxx::DeleteFolder(LPCTSTR loFolder)
{
    CFileFind    fFind;
    CString strFolderPath = loFolder;
    strFolderPath.TrimRight( _T("\\") );
    strFolderPath += _T("\\*.*");

    if( !fFind.FindFile( strFolderPath ) )
        return FALSE;

    BOOL bRet = TRUE;
    while( bRet ){
        bRet = fFind.FindNextFileW();

        if( fFind.IsDots() )
            continue;

        CString strPath;
        strPath.Format( _T("%s\\%s"), loFolder, fFind.GetFileName() );

        if( fFind.IsDirectory() )
            DeleteItem( strPath );
        else
            DeleteFile( strPath );
    }
    fFind.Close();

    return RemoveDirectory( loFolder );
}

PR
フォルダを分割する。


BOOL xxxxxx::SplitFolder(CString FolderPath, CStringArray& FolderList )
{
    int iPos = 0;

    FolderList.RemoveAll();

    while( iPos != -1 ){

        CString str = FolderPath.Tokenize( _T("\\"), iPos );
        FolderList.Add( str );

    }

    if( FolderList.GetSize() == 0 ) return FALSE;

    return TRUE;
}


フォルダを作成する。


BOOL xxxxxx::CreateFolder(LPCTSTR lpFolderName)
{

    // 指定したフォルダをチェックと作成
    CString folder = _T("");
    LPSECURITY_ATTRIBUTES lpSecurity;

    CStringArray splitFolder;
    this->SplitFolder( lpFolderName, splitFolder );

    for( int i = 0; i < splitFolder.GetSize() - 1; i++ ){
        folder += splitFolder.GetAt(i);

        if( !this->CheckFolderPath( folder ) ){
            if(::CreateDirectory( /*(LPCWSTR)*/folder, NULL ) == NULL ){
                ::AfxMessageBox( _T("フォルダの作成に失敗しました。") );
                return FALSE;
            }
        }
        folder += _T("\\");
    }
    return TRUE;
}

指定したフォルダの存在をチェックする


BOOL xxxxxx::CheckFolderPath(CString FolderPath)
{
    // フォルダ確認
    if( ::PathFileExists( FolderPath ) ){
        return true;
    }

    return false;
}

CStringをLPTSTRへ変換する


LPTSTR xxxxxx::CStringToLptstr(CString strData)
{
    LPTSTR str    = new TCHAR[ strData.GetLength() + 1 ];
    _tcscpy( str, strData );

    return str;
}

カレンダー
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]