【小程序】findobj

简介:

为了方便开发,实验室的师哥给了一个小任务,写一个小程序,完成以下功能:给一个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;
}


相关文章
|
9月前
|
存储 小程序 JavaScript
小程序 globalData
小程序 globalData
47 0
|
11月前
|
小程序
关于打卡小程序可能会遇到的部分问题
关于打卡小程序可能会遇到的部分问题
71 0
关于打卡小程序可能会遇到的部分问题
程序人生 - 2025年社保卡将覆盖全国
程序人生 - 2025年社保卡将覆盖全国
80 0
程序人生 - 2025年社保卡将覆盖全国
|
Web App开发 移动开发 人工智能
小程序的新战事
小程序的新战事
120 0
小程序的新战事
如何跳小程序
       经常会有人遇到这样的疑惑——        我有自己的APP、生活号或在支付宝端内有自己的H5页面,这种情况下如何和小程序关联,跳转到小程序里去,做到无缝对接?        其实,小程序是支持这类跳转能力的;        那么,要如何实现呢?        一、非小程序前端——跳转小程序 window.
617 0
|
算法
循序渐进写程序
【来信】   老师,我现在是初学编程,感觉自己的编程能力比较弱,如果做一道算法题,有时候需要两三个小时,做出来之后还没有答案上给的算法好,应该是练习比较少,我是应该多看别人写好的算法,然后多敲代码好呢,还是尽量自己写,写不出来再看答案好呢(感觉自己写好浪费时间) 【回复】   我们的学习,要讲究循序渐进。你出现这种情况,应该是做的题目中,包含了太多对你而言是“新知识”的
989 0
|
C++ 小程序
C++ 实用的小程序
1. 打开test_ids.txt 将里面的东西添加"1_",然后另存为test_ids_repaired.txt   1 #include 2 #include 3 #include 4 #include 5 #include 6 using name...
951 0
|
C++ 存储
C++电话本程序
/* C++电话本程序 */ /* 1.可实现txt文件的读取和保存。 */ /* 2.可实现联系人的增添、删除和修改。 */ /* 3.可实现通过联系人查询号码。 */ /* 4.可实现通过号码查询联系人。 */ /* 5.可实现全部联系人的显示。 */ /* 运行环境vs2010||codebl
996 0