您的位置:首页 > 其它

win32控制台下实现查找并显示指定目录下的指定类型文件

2012-10-25 17:40 691 查看
// FindFileTest.cpp : 定义控制台应用程序的入口点。

//

#include "stdafx.h"

#include <Windows.h>

#include <atlstr.h>

#include <iostream>

using namespace std;

int _tmain(int argc, _TCHAR* argv[])

{

/**************

宽字节 字符的控制台输出 添加下面转化函数

**************/

locale loc("chs"); //定义“区域设置”为中文方式

wcout.imbue(loc); //载入中文字符输入方式

/**************

查找并显示指定目录下的指定类型文件

***************/

WIN32_FIND_DATA FindFileData;

HANDLE hFind;

CString dir;

dir=L"D:\\*.txt";

LPCTSTR bufDir;

bufDir=(LPCTSTR)dir;

wcout << L"Target file is " << bufDir << endl;

hFind = FindFirstFile(bufDir, &FindFileData);

if (hFind == INVALID_HANDLE_VALUE)

{

wcout << L"Invalid File Handle. GetLastError reports " << GetLastError () << endl;

return 0;

}

else

{

wcout << L"The first file found is " << FindFileData.cFileName << endl;

CString temp = FindFileData.cFileName;

cout<<temp;

FindClose(hFind);

system("pause");

}

return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: