什么方法可以得到一个文件夹里头的所有子文件?给点提示 或者把重要代码贴出来一下 3Q3Q

解决方案 »

  1.   

    用 CopyFile(...) 和 *.*
      

  2.   

    1 主要是用递归的方法。
    2 给你一个TreeCtrl的例子.void CFileTreeDlg::AddFile(CString StrPath, HTREEITEM faItem )
    //StrPath为传递过来的目录层次,本次函数调用中搜索的文件都是它的下一层的。
    //faItem为传递过来的Tree节点,本次函数调用中添加的Tree节点都是它的子节点。
    {
    CFileFind OneFile;
    CString FName, DirName;
    BOOL BeWorking; 
    HTREEITEM NewItem; DirName = StrPath+"\\*.*";
    BeWorking = OneFile.FindFile( DirName );
    while ( BeWorking ) {   //BeWorking非零,指找了文件或目录 //查找同级的目录
    BeWorking = OneFile.FindNextFile(); if ( OneFile.IsDirectory() && !OneFile.IsDots() )        //如果查找的结果是目录又不是".."或"."
    {
    //向Tree1中添加目录;
    DirName = OneFile.GetFilePath();
    FName = OneFile.GetFileTitle(); 
    //IDC_TREE1
    NewItem = m_Tree.InsertItem( FName, faItem );    //NewItem取得节点,其目的是为了下一层中
     //添加节点方便,递归时把它传过去。
    //进入下一层递归调用。
    AddFile(DirName, NewItem);
    } //退出递归时,到了这里!!!
    if ( !OneFile.IsDirectory() && !OneFile.IsDots() )       //如果查找结果是文件
    {
    //向Tree1中添加文件
    FName = OneFile.GetFileTitle();  //注意这里用的是GetFileTitle,因为
     //这里是添加文件。
    m_Tree.InsertItem( FName, faItem );
    }
    }// end of while

    OneFile.Close(); //记着用完CFileFild实例要关闭
    }
      

  3.   

    http://www.vckbase.net/document/viewdoc/?id=806
      

  4.   

    用IShellFolder::EnumObjectsA Simple Example of How to Use ShellExecuteEx
    The following sample console application illustrates the use of ShellExecuteEx. Most error checking code has been omitted for clarity.#include <shlobj.h>
    #include <shlwapi.h>main()
    {
        LPMALLOC pMalloc;
        LPITEMIDLIST pidlWinFiles = NULL;
        LPITEMIDLIST pidlItems = NULL;
        IShellFolder *psfWinFiles = NULL;
        IShellFolder *psfDeskTop = NULL;
        LPENUMIDLIST ppenum = NULL;
        STRRET strDispName;
        TCHAR pszParseName[MAX_PATH];
        ULONG celtFetched;
        SHELLEXECUTEINFO ShExecInfo;
        HRESULT hr;
        BOOL fBitmap = FALSE;    hr = SHGetMalloc(&pMalloc);

        hr = SHGetFolderLocation(NULL, CSIDL_WINDOWS, NULL, NULL, &pidlWinFiles);    hr = SHGetDesktopFolder(&psfDeskTop);    hr = psfDeskTop->BindToObject(pidlWinFiles, NULL, IID_IShellFolder, (LPVOID *) &psfWinFiles);
        hr = psfDeskTop->Release();    hr = psfWinFiles->EnumObjects(NULL,SHCONTF_FOLDERS | SHCONTF_NONFOLDERS, &ppenum);    while( hr = ppenum->Next(1,&pidlItems, &celtFetched) == S_OK && (celtFetched) == 1)
        {
            psfWinFiles->GetDisplayNameOf(pidlItems, SHGDN_FORPARSING, &strDispName);
            StrRetToBuf(&strDispName, pidlItems, pszParseName, MAX_PATH);
            pMalloc->Free(pidlItems);
            if(StrCmpI(PathFindExtension(pszParseName), TEXT( ".bmp")) == 0)
            {
                fBitmap = TRUE;
                break;
            }
        }

        ppenum->Release();    if(fBitmap)
        {
            ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
            ShExecInfo.fMask = NULL;
            ShExecInfo.hwnd = NULL;
            ShExecInfo.lpVerb = NULL;
            ShExecInfo.lpFile = pszParseName;
            ShExecInfo.lpParameters = NULL;
            ShExecInfo.lpDirectory = NULL;
            ShExecInfo.nShow = SW_MAXIMIZE;
            ShExecInfo.hInstApp = NULL;        ShellExecuteEx(&ShExecInfo);
        }    pMalloc->Free(pidlWinFiles);
        pMalloc->Release();
        psfWinFiles->Release();    return 0;
    }