rai002 @ ウィキ
ファイルリストの作成(階層を潜らない)(上記の改造)
最終更新:
rai002
-
view
//**********************************************************************
// ファイルリストの作成(階層を潜らない)
// [引数]
// sFindDir : 検索するフォルダ,
// sFindFile : 検索条件
// rank : 階層
// [戻り値]
// ファイルの数
//**********************************************************************
int get_dir::filelist_user(const char *sFindDir, const char *sFindFile, vector<string > &tempDir)
{
int iFiles = 0; // ファイル数カウント
DATA temp_data;
// 検索パスの作成
char sFindPath[MAX_NAME_NUMBER];
if (strlen(sFindDir) > MAX_NAME_NUMBER -(strlen(sFindFile)+2) ) {// バッファー長のチェック
return 0;
string tstr("アドレスの長さがオーバーしました。");
tstr += sFindDir;
tstr += sFindFile;
MessageBoxA(NULL, tstr.c_str(), "警告" , MB_OK);
}
strcpy(sFindPath, sFindDir);
strcat(sFindPath, "\\");
strcat(sFindPath, sFindFile);
// 検索
WIN32_FIND_DATAA FindFileData;
HANDLE hFind = FindFirstFileA( sFindPath , &FindFileData);
if(hFind != INVALID_HANDLE_VALUE){
do{
string str( (char *)FindFileData.cFileName );
//除外フォルダのときは抜ける
if( UnSearch( str ) ) break;
if( str =="." || str == ".." || str.empty() ) {} // '.'と'..'以外のとき
else if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_SYSTEM) {} //システム属性を持つとき
else if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_HIDDEN) {} //隠し属性を持つとき
else if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_TEMPORARY) {} //一時属性を持つ
else if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_SPARSE_FILE) {} //スーパーファイル
else { //ディレクトリ時
//cout << "name_;" << FindFileData.cFileName << endl;
// '.'と'..'以外のとき
// サブフォルダの処理
char sFindSubDir[ MAX_PATH_NAME ];
strcpy(sFindSubDir, sFindDir);
strcat(sFindSubDir, "\\");
strcat(sFindSubDir, str.c_str());
tempDir.push_back( sFindSubDir );
iFiles ++;
}
} while(FindNextFileA(hFind, &FindFileData));
//cout << endl;
FindClose(hFind);
}else{
//cout << "ファイルがありません(" << sFindDir << ")\n";
no_data.push_back( sFindDir );
}
return iFiles;
}