假设有一个文件a.html,需要将它发送到a目录下面的子文件夹下,a目录文件名不变,子文件夹名字每次开机会改变名字,小白一个,希望给个完整源码:能将a.html发送到指定目录下的所有子文件夹中(不是MFC的,是控制台的)
1条回答 默认 最新
- threenewbee 2018-10-17 03:20关注
// 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; }
解决 无用评论 打赏 举报
悬赏问题
- ¥50 有数据,怎么建立模型求影响全要素生产率的因素
- ¥50 有数据,怎么用matlab求全要素生产率
- ¥15 TI的insta-spin例程
- ¥15 完成下列问题完成下列问题
- ¥15 C#算法问题, 不知道怎么处理这个数据的转换
- ¥15 YoloV5 第三方库的版本对照问题
- ¥15 请完成下列相关问题!
- ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
- ¥15 求daily translation(DT)偏差订正方法的代码
- ¥15 js调用html页面需要隐藏某个按钮