|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
小小成就,高手勿喷!- #include "stdafx.h"
- #include <Windows.h>
- #include <stdio.h>
- #include <string.h>
- #include <direct.h>
- #include <io.h>
- int _tmain(int argc, _TCHAR* argv[])
- {
- FILE *fp1;
- char buffer1[1024];
- memset(buffer1, 0, 1024);
- struct _finddata_t fa;
- long fHandle;
- char* buffer, *strl;
- WCHAR* str2;
- strl = "\\*.txt";
- //得到当前的工作路径
- if((buffer=_getcwd(NULL,0))==NULL)
- {
- perror("_getcwderror");
- }
- else
- {
- printf("%s\nLength:%d\n",buffer,strlen(buffer));
- }
- strcat(buffer, strl);
- if( (fHandle = _findfirst(buffer, &fa )) == -1L ) //这里可以改成需要的目录 //c:*.txt
- {
- printf( "当前目录下没有txt文件\n" );
- return 0;
- }
- else
- {
- do
- {
- printf( "找到文件:%s\n", fa.name );
- str2 = (WCHAR*)fa.name;
- fp1 = fopen(fa.name,"r");
-
- while(fgets(buffer1,1024,fp1) != NULL)
- {
- printf(" %s\n\n ",buffer1);
- }
- }while( _findnext(fHandle,&fa) == 0 );
- _findclose( fHandle );
- return 0;
- }
-
- fclose(fp1);
- free(buffer);
- return 0;
- }
复制代码
|
|