를 사용하여 읽는 동안 디렉토리를 생략하는 방법 : 내가 실패한 디렉토리를 건너 뛰도록 만들 수 없습니다 을 열기 위해. 내가 할 수있는 디렉토리를 열어서 실패 할 수없는 디렉토리를 건너 뛰고 실패로 끝나는 대신 다음 디렉토리로 이동하기를 원합니다. 이 문제를 해결하려면 어떻게해야합니까? 여기 내가</strong></p> <p>내 문제가 <strong>dirent.h를에서 제공하는 기능을 사용하여 재귀 적으로 파일을 열 노력하고 dirent.h를
내가windows 7
에이 같은 스타일을 사용
int acessdirs(const char *path)
{
struct dirent *entry;
DIR *dp;
char fpath[300];
if(dp=opendir(path))
{
while((entry=readdir(dp)))
do things here
}
else
{
std::cout<<"error opening directory";
return 0;
}
return 1;
}
를 사용하려고 간단한 코드이며, 그것은 windows xp
에 추락 됐었 작동하고 내가 그것을 디버깅 할 때 내가하려고하는 동안 충돌 발견 "system volume information"
을여십시오. 난 정말이 폴더에 액세스 할 필요가 없으며 그것을 건너 뛸 방법이 있다면 나는 기대했다.
내 실제 코드는 다음과 같습니다.
조금 깁니다.
int listdir(const char *path)
{
struct dirent *entry;
DIR *dp;
if(dp = opendir(path))
{
struct stat buf ;
while((entry = readdir(dp)))
{
std::string p(path);
p += "\\";
p += entry->d_name;
char fpath[300];
if(!stat(p.c_str(), &buf))
{
if(S_ISREG(buf.st_mode))
{
sprintf(fpath,"%s\\%s",path,entry->d_name);
stat(fpath, &buf);
std::cout<<"\n Size of \t"<<fpath<<"\t"<<buf.st_size;
fmd5=MDFile (fpath);
}//inner second if
if(S_ISDIR(buf.st_mode) &&
// the following is to ensure we do not dive into directories "." and ".."
strcmp(entry->d_name, ".") && strcmp(entry->d_name, ".."))
{
listdir(p.c_str());
}
}//inner first if
else
std::cout << "ERROR in stat\n";
}//end while
closedir(dp);
}//first if
else
{
std::cout << "ERROR in opendir\n";
return 0;
}
return 1;
}//listdir()
'access'는 두 개의 'c'로 표기됩니다. – hochl
이 코드는 어떻게 컴파일됩니까? 당신은'dip'이라는 변수를 가지고 있고 이것을'dp'라고 부릅니다. 또한 앞으로는 이해할 수 있도록 코드를 들여 씁니다. – Celada
문제가있는 곳을 이해하는 데 너무 적은 코드를 붙여 넣었습니다. 'accessdirs'가 루프에서 호출됩니까? '0'이 반환되면 루프가 무엇을합니까? 재귀는 정확히 어디에 있습니까? "여기에있는 일"이 "액세스 디렉토리"를 호출합니까? –