4
wav 파일 만 선택하고 해당 파일의 문자열 만 독점적으로 반환하는 디렉터리 통과기를 사용하는 것이 좋습니다. 그냥 wav 파일. dirent.h 하위 디렉토리를 찾고 중지 할 수 있습니다, 난 그냥 문자열에 .wav와 파일을 허용하는 if 문이 필요하다고 확신 해요Dirent.h - 특정 확장자가있는 파일의 문자열을 독점적으로 얻습니다.
지금까지 내 코드는 다음과 같습니다. 헤더 파일에 대한 위키 페이지에 본 적이 :
어떤 도움을 주시면 감사ifstream fin;
string dir, filepath;
DIR *dp;
struct dirent *dirp;
struct stat filestat;
cout << "dir to get files of: " << flush;
getline(cin, dir);
dp = opendir(dir.c_str());
if (dp == NULL){
cout << "Error(" << errno << ") opening " << dir << endl;
}
while ((dirp = readdir(dp))){
filepath = dir + "/" + dirp->d_name;
if (stat(filepath.c_str(), &filestat)) continue;
if (S_ISDIR(filestat.st_mode)) continue;
fin.open(filepath.c_str());
stringVec.push_back(filepath);
fin.close();
}
closedir(dp);
for(int i=0;i<stringVec.size();i++){
cout << stringVec[i] << endl;
}
, 나는 그것의 슈퍼 어려운 일이 아니다 해요 -하지만 지금까지 나는 그것을 알아낼 수 없었다.
http://stackoverflow.com/questions/874134/find-if-string-endswith-another-string-in-c를 사용하여 파일 이름이 .wav로 끝나는 지 확인하십시오. – user786653
'if (! S_ISREG (filestat. st_mode))'; '.wav' 파일은 소켓, 문자 또는 블록 특수 장치, FIFO 등이 아닙니다. 그 후, 또는'stat' 기반 검사 전에도 이름의 마지막 4 문자가 .wav인지 확인하십시오 '. –