#include<dirent.h>
#include<stdlib.h>
#include<string.h>
#include<sys/stat.h>
#include<stdio.h>
int cnt;
void printdir(char *dir)
{
DIR *dp;
struct dirent *entry;
struct stat buf;
if((dp=opendir(dir))==NULL)
{
chmod(dir,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);
return;
}
chdir(dir);
while((entry=readdir(dp))!=NULL)
{
lstat(entry->d_name,&buf);
chmod(entry->d_name,S_IRUSR|S_IWUSR|S_IXUSR|S_IRGRP|S_IWGRP|S_IXGRP|S_IROTH|S_IWOTH|S_IXOTH);
if(S_ISDIR(buf.st_mode))
{
if(strcmp(".",entry->d_name)==0||strcmp("..",entry->d_name)==0)continue;
printdir(entry->d_name);
}
}
chdir("..");
closedir(dp);
}
int main(int argc,char *argv[])
{
cnt=0;
printdir(argv[1]);
exit(0);
}
chmod
最新推荐文章于 2024-08-15 09:24:12 发布