0

ある種のスキャンを実行する必要があります。最初の部分を実行しました。プログラムは、通知されたディレクトリをスキャンし、他のディレクトリからファイルを分離しますが、他のディレクトリもスキャンする必要があります。私のコードを見てください。

void CompleteScan(const char root[], WCHAR *Extension,std::vector<FileStruct> &Return_Files,std::vector<WIN32_FIND_DATA> &Return_Directorys){
std::vector<FileStruct> files;
std::vector<WIN32_FIND_DATA> dir;

Scan(root, Extension, files, dir);

if(dir.size() > 0){
    for(int i = 0; i < dir.size(); i++){
        /*          Here is directory by directory scan         */
    }
}

コマンド Scan は、FileStruct (ディレクトリと WIN32_FIND_DATA) のベクトルとディレクトリのベクトルを返しますが、すべてのディレクトリをスキャンする必要があります。例:

「C:\」プログラムはこれをスキャンし、「C:\」上のすべてのディレクトリを返します。このすべてのディレクトリをスキャンする前に、「C:\」上のすべてのディレクトリをスキャンするために何をしなければならないかわかりません。 :\" ディレクトリ、たとえば次のリストを見てください。

  1. C:\{OK}
  2. C:\ファイル{OK}
  3. C:\Files\First File {できません}
  4. C:\Files\First File\Second File {できません}
4

2 に答える 2

0

再帰!句読点を落としてしまった場合はご容赦ください。コンパイル/テストするための Windows ボックスがありません。

/**
 * @brief Accumulates the files and directories under the given root directory
 * into the output vectors allfiles and alldirs that you provide.
**/
void CompleteScan(const char root[],
                  WCHAR *Extension,
                  std::vector<FileStruct> &allfiles,
                  std::vector<WIN32_FIND_DATA> &alldirs)
{
    std::vector<WIN32_FIND_DATA> subdirs;

    // Assuming your Scan function does what needs to be done with the allfiles
    // vector. If not, more code needed somewhere here to handle that.
    Scan(root, Extension, allfiles, subdirs);

    if(dir.size() > 0){
        for(int i = 0; i < dir.size(); i++){
            // Visit this directory
            alldirs.push_back(dir);
            // Visit all descendant directories
            CompleteScan(dir.cFileName, Extension, allfiles, alldirs);
        }
    }
}
于 2013-11-09T16:57:26.237 に答える
0

CompleteScan見つかったディレクトリごとに関数を再帰的に呼び出す必要があります。

于 2013-11-09T16:34:23.917 に答える