//pwd显示当前所在目录的路径名
void mypwd(){
char catalogue[100];
getcwd(catalogue,sizeof(catalogue));//绝对路径,空间大小
cout<<"所在目录的路径名:"<<catalogue<<endl;
}
//list列出指定目录名中的所有目录及文件
int mylist(){
char catalogue[100];
cout<<"请输入你需要寻找的目录:"<<endl;
cin>>catalogue;
const char *a=catalogue;//指针
DIR *b; //句柄b
struct dirent *file; //readdir返回值
int len = 0;
int i;
char filename[256][256];
if(!(b = opendir(a))) //如果目录不存在
{
cout<<catalogue<<"目录不存在"<<endl;
return -1;
}
while((file = readdir(b)) != NULL){
if(strncmp(file->d_name, ".", 1) == 0) //把当前目录'.',上一级目录'..'去除
continue;
strcpy(filename[len++], file->d_name); //保存文件名
}
closedir(b);
for(i = 0; i < len; i++)
{cout<<filename[i]<<" ";}
cout<<endl;
return 0;
}