[CPP] View plain copy on code to view the snippet derived to my code slice began to think it was a very simple problem later found a little trouble, finally implemented as follows, where TMP is the type of file to find, change to other such as. java can find Java type file name [CPP ] View plain copy on code to see a snippet derived from my Code slice <pre code_snippet_id= "266604" snippet_file_name= "blog_20140331_2_3829526" Name= "code" class= "CPP" > #include <iostream> #include <dirent.h> using namespace std; int main (void) {dir* dirp; struct dirent* direntp; DIRP = Opendir ("F:\\output\\codegen"); string tmp = ". txt"; string filename; if (dirp! = NULL) {for (;;) {direntp = Readdir (DIRP); if (direntp = = NULL) break; string s = direntp->d_name; int x = S.find (tmp,0); if (x>0) {string last; Last.assign (S,0,X); Filename=last; FileName is the name of the TXT file, does not contain the TXT suffix, and the added. txt suffix after the name can be opened directly for other operations}} closedir (DIRP); } cout<<filename<<endl; return 0; }</pre><br> <br> <pre></pre> <pre></pre>
Forward-c++ implement find files under folder