我必须模拟存储在CD / DVD上的数据。
我有3个班级:
对于每种类型的CD / DVD,我必须显示安装在计算机上的应用程序 允许访问它(不同的播放器用于音乐/电影,或各种游戏的单人纸牌)。
如何找到所有exe程序? 我使用下一个函数(但它只在指定的文件夹中找到)。
#include<stdio.h>
#include<cstdlib>
#include<iostream>
#include<string.h>
#include<fstream>
#include<dirent.h>
void listFile();
int main()
{
listFile();
return 0;
}
void listFile(){
int l=0;
DIR *pDIR;
struct dirent *entry;
if( pDIR=opendir("C:\\Users\\A\\Desktop") ){
while(entry = readdir(pDIR)){
if( strcmp(entry->d_name, ".") != 0 && strcmp(entry->d_name, "..") != 0 )
{
l=strlen(entry->d_name);
if(entry->d_name[l-1]=='e')
if(entry->d_name[l-2]=='x')
if(entry->d_name[l-3]=='e')
if(entry->d_name[l-4]=='.')
{
string x;
x=entry->d_name;
cout<<x<<endl;
}
}
}
closedir(pDIR);
}
}
答案 0 :(得分:0)
您必须使用OS API,因为标准C ++库没有列出目录或文件夹及其内容的规定。
您的基本算法是在每个文件夹上执行“for each”:
我无法告诉您使用哪个API,因为您没有在您的问题中指定您的平台,操作系统和编译器(请使用相关信息编辑您的问题)。