编两个小程序
来源:百度知道 编辑:UC知道 时间:2024/06/04 05:11:16
文件内容如下:
1
name:"A"
path:"X:\123\A"
2
name:"I can play.mp3"
path:"X:\music\I can play.mp3"
3
name:"What.doc"
path:"X:\doc\What.doc"
...//格式雷同
另有一程序,运行后出现一个索引界面,输入要索引的文件名后,在file.txt中查找该文件名,找到后输出文件名及路径,找不到则反馈无
#include <iostream>
#include <windows.h>
#include <cstring>
#include <fstream>
using namespace std;
ofstream ofs("file.txt");
void ListFile(char* szDir)
{
char szTempDir[MAX_PATH+1];
strcpy(szTempDir,szDir);
strcat(szTempDir,"*");
HANDLE hFindFile;
WIN32_FIND_DATA FileData;
hFindFile = FindFirstFile(szTempDir,&FileData);
if( hFindFile == INVALID_HANDLE_VALUE )
{
return ;
}
else
{
do
{
if( (FileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
&& strcmp(FileData.cFileName,".")
&& strcmp(FileData.cFileName,".."))
{
char szNewDir[MAX_PATH+1];
strcpy(szNewDir,szDir);
strca