呵呵~~~非常感谢你啊guohao!!!
不过出了点点问题就是不能在一个目录中的多个文本文件中搜索指定字符串的出现
这下边是我们老师的一个提醒:// _findfirst2.cpp : Defines the entry point for the application.
//
#include "stdafx.h"
#include
#include
#include
#include
#include
#include "shellapi.h"
#include "shlobj.h"
using namespace std;
void EnumerateFolders ();
void EnumerateFiles ();
int APIENTRY WinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance,
LPSTR lpCmdLine,
int nCmdShow)
{
// TODO: Place code here.
LPITEMIDLIST pidlSelected = NULL;
char temp[MAX_PATH];
LPSTR pszPath=temp;
BROWSEINFO bi = {0};
bi.hwndOwner = NULL;
bi.pidlRoot = NULL;
bi.pszDisplayName = NULL;
bi.lpszTitle = "请选择一个文件夹";
bi.ulFlags = 0;
bi.lpfn = NULL;
bi.lParam = 0;
pidlSelected = SHBrowseForFolder(&bi);
SHGetPathFromIDList(pidlSelected,pszPath);
if(SetCurrentDirectory(pszPath)){
MessageBox(NULL,pszPath,"你选择的文件夹是",MB_OK);
//以上选择了一个文件夹并将其路径存放在pszpath中
MessageBox(NULL,"输出的内容保存在c:\\fileofdirectory.txt中并将用记事本打开","输出内容保存",MB_OK);
}
EnumerateFolders();//输出文件夹
//在文件夹和文件之间插入一个空行
const string& filename="c:\\fileofdirectory.txt";
ofstream file(filename.c_str(),std::ios::app);
file<
EnumerateFiles();//输出文件
ShellExecute(NULL, "open","fileofdirectory.txt", NULL, "c:", SW_MAXIMIZE);
return 0;
}
void EnumerateFolders ()
{
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile ("*.*", &fd);
if (hFind != INVALID_HANDLE_VALUE)
{
const string& filename="c:\\fileofdirectory.txt";
ofstream file(filename.c_str());
do {
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
const string& name = fd.cFileName;
if (name != "." && name !="..")file<}
}
while (::FindNextFile (hFind, &fd));
::FindClose (hFind);
}
}
void EnumerateFiles ()
{
WIN32_FIND_DATA fd;
HANDLE hFind = ::FindFirstFile ("*.*", &fd);
if (hFind != INVALID_HANDLE_VALUE)
{
do {
const string& filename="c:\\fileofdirectory.txt";
ofstream file(filename.c_str(),std::ios::app);
if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY);
else{
const string& name = fd.cFileName;
if (name != "." && name !="..")file<}
}
while (::FindNextFile (hFind, &fd));
::FindClose (hFind);
}
}
--------------------next---------------------
阅读(1056) | 评论(0) | 转发(0) |