怎么将一个文件拷贝到指定目录下的所有子文件夹中

假设有一个文件a.html,需要将它发送到a目录下面的子文件夹下,a目录文件名不变,子文件夹名字每次开机会改变名字,小白一个,希望给个完整源码:能将a.html发送到指定目录下的所有子文件夹中(不是MFC的,是控制台的)

// Q702781.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

//参考了 https://blog.csdn.net/liigo/article/details/4548577

#include "windows.h"
#include "stdio.h"

typedef BOOL (WINAPI *EnumerateFunc) (LPCSTR lpFileOrPath, void* pUserData);

void doFileEnumeration(LPSTR lpPath, BOOL bRecursion, BOOL bEnumFiles, EnumerateFunc pFunc, void* pUserData)
{

    static BOOL s_bUserBreak = FALSE;
    try{
        //-------------------------------------------------------------------------
        if(s_bUserBreak) return;

        int len = strlen(lpPath);
        if(lpPath==NULL || len<=0) return;

        //NotifySys(NRS_DO_EVENTS, 0,0);

        char path[MAX_PATH];
        strcpy(path, lpPath);
        if(lpPath[len-1] != '//') strcat(path, "//");
        strcat(path, "*");

        WIN32_FIND_DATA fd;
        HANDLE hFindFile = FindFirstFile(path, &fd);
        if(hFindFile == INVALID_HANDLE_VALUE)
        {
            ::FindClose(hFindFile); return;
        }

        char tempPath[MAX_PATH]; BOOL bUserReturn=TRUE; BOOL bIsDirectory;

        BOOL bFinish = FALSE;
        while(!bFinish)
        {
            strcpy(tempPath, lpPath);
            if(lpPath[len-1] != '//') strcat(tempPath, "//");
            strcat(tempPath, fd.cFileName);

            bIsDirectory = ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0);

            if( bIsDirectory
                && (strcmp(fd.cFileName, ".")==0 || strcmp(fd.cFileName, "..")==0)) 
            {       
                bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
                continue;
            }

            if(pFunc && bEnumFiles!=bIsDirectory)
            {
                bUserReturn = TRUE; // pFunc(tempPath, pUserData);
                if(bUserReturn==FALSE)
                {
                    s_bUserBreak = TRUE; ::FindClose(hFindFile); return;
                }
            }

            //NotifySys(NRS_DO_EVENTS, 0,0);

            if(bIsDirectory && bRecursion) 
            {
                pFunc(tempPath, pUserData);
                doFileEnumeration(tempPath, bRecursion, bEnumFiles, pFunc, pUserData);
            }

            bFinish = (FindNextFile(hFindFile, &fd) == FALSE);
        }

        ::FindClose(hFindFile);

        //-------------------------------------------------------------------------
    }catch(...){ return; }
}

char dirtocopy[] = "C:\\填写你的目录";
char filetocopy[] = "C:\\填写你的文件带路径\\a.html";
char filename[] = "\\填写你的文件名不带路径.html";

BOOL WINAPI myEnumerateFunc(LPCSTR lpFileOrPath, void* pUserData)
{
    //char* pdot;
    //if((pdot = strrchr(lpFileOrPath, '.')) && stricmp(pdot, ".mp3") == 0)
    //{
    //  printf("%s\n", lpFileOrPath);
    //}
    printf("%s\n", lpFileOrPath);
    char filenametocopy[400];
    strcpy(filenametocopy, lpFileOrPath);
    strcat(filenametocopy, filename);
    CopyFile(filetocopy, filenametocopy, TRUE);
    return TRUE;
}

int main(int argc, char* argv[])
{
    doFileEnumeration(dirtocopy, TRUE, TRUE, myEnumerateFunc, NULL);
    return 0;
}


完整代码:https://download.csdn.net/download/caozhy/10726127