【小程序】findobj

来源:互联网 发布:程序员联合开发 编辑:程序博客网 时间:2024/05/04 16:06

为了方便开发,实验室的师哥给了一个小任务,写一个小程序,完成以下功能:给一个txt文档,里面有一些文件名,这些文件是要求找出的;给一个目录路径,里面可能包含这个txt中指定的文件(也可能没有);如果某个文件存在就把它复制到另一个指定文件夹里面。


写了一个80来行的程序,程序木有界面,缺点是不能遍历指定文件夹中的嵌套文件夹。

#include<stdio.h>#include<stdlib.h>#include<string.h>#include<io.h>char tFPath[60];char dFPath[20];bool findFiles(char *fileName){long Handle;struct _finddata_t FileInfo;char path[60];strcpy(path,tFPath);strcat(path,"\\");strcat(path,fileName);printf("path == %s\n",path);if((Handle=_findfirst(path,&FileInfo))==-1L){printf("sorry, no such file!\n");return false;}else{printf("Find it:%s\n",FileInfo.name);char SysOrder[100]="copy ";strcat(SysOrder,path);strcat(SysOrder," ");strcat(SysOrder,dFPath);system(SysOrder);_findclose(Handle);return true;}return true;}int main(){FILE *fp=NULL;char fileName[30];char a;char txtSrc[30];printf("Please enter the TXT Source file path:\n");scanf("%s",txtSrc);fp=fopen(txtSrc,"r");printf("Please enter the target folder path:\n");scanf("%s",tFPath);printf("Please enter the destination folder path:\n");scanf("%s",dFPath);int i=0;do{a=fgetc(fp);if (a!='\n')fileName[i++]=a;else{fileName[i]='\0';findFiles(fileName);i=0;}}while(a!=EOF);fclose(fp);getchar();return 0;}


0 0
原创粉丝点击