Good thing or not. I felt something.
21 :// 22 :// it refers all to 23 :// https://stackoverflow.com/questions/11362771/list-files-in-directory-c 24 :// https://bituse.info/winapi/31 25 :// 26 :// Parameters 27 :// 28 :// lpcstr_path 29 :// 30 :// Directory name which is going to be found files. 31 :// 32 :// Return Value 33 :// 34 :// char** 35 :// 36 :// File list under the lpcstr_path, which has fullpath. 37 :// 38 :char** FileControler::get_files ( char* lpcstr_path, int* file_num ) { 39 : WIN32_FIND_DATA ffd; 40 : HANDLE hFind = INVALID_HANDLE_VALUE; 41 : char* ffdc_filename; 42 : int dummy_filenum = 0; 43 : char* char_asterisk_path = "\0"; // .\abc\* if .\abc\*.php 44 : char* char_attr = "\0"; 45 : int cnt = 0; 46 : int cnt_char_asterisk_path = 0; 47 : 48 : DEBUG( (char *)"get_files", "lpcstr_path: %s file_num: %d\r\n", (char*)lpcstr_path, *file_num ); 49 : 50 : // Prepare string for use with FindFile functions. First, copy the 51 : // string to a buffer, then append '\*' to the directory name. 52 : cnt = array_count(lpcstr_path); 53 : int search_length = m_last_with( lpcstr_path, "."); 54 : if ( search_length <= 0 ) { 55 : 56 : hFind = FindFirstFile( TEXT( lpcstr_path ), &ffd ); 57 : char_asterisk_path = lpcstr_path; 58 : } else { 59 : 60 : // In this case, lpcstr_path is like ".\abc\*.php" 61 : char_asterisk_path = substring( lpcstr_path, 0, search_length ); 62 : cnt_char_asterisk_path = array_count( char_asterisk_path ); 63 : char_attr = substring( lpcstr_path, search_length, cnt - cnt_char_asterisk_path ); // max_count:cnt 64 : hFind = FindFirstFile( TEXT( char_asterisk_path ), &ffd ); 65 : } 66 : 67 : ffdc_filename = copyof( (char*)ffd.cFileName ); 68 : printf("char_attr: %s search_length: %d char_asterisk_path: %s lpcstr_path %s\r\n", char_attr, search_length, char_asterisk_path, lpcstr_path ); 69 : 70 : int index = 0; 71 : // List all the files in the directory with some info about them. 72 : do 73 : { 74 : ffdc_filename = copyof( (char*)ffd.cFileName ); 75 : //DEBUG( (char *)"get_files", "ffdc_filename: %d: %s attribute %d\r\n", index, ffdc_filename, is_attribute ( ffdc_filename, char_attr ) ); 76 : index++; 77 : char* char_directory = to_directory ( char_asterisk_path, ffdc_filename ); 78 : 79 : if ( char_directory == NULL || m_compare( ffdc_filename, (char*)".") == 1 || m_compare( ffdc_filename, (char*)"..") == 1 ) { 80 : 81 : //DEBUG( (char *)"get_files", "skip away : %s\r\n", ffdc_filename ); 82 : 83 : } else { 84 : 85 : if ( is_attribute ( ffdc_filename, char_attr ) == 1 ) { 86 : this->put_string ( char_directory ); 87 : } 88 : 89 : if ( ffd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) { 90 : //char* listfiles = (char*) m_concat( (char*)char_directory, (char*)"\\*." ); 91 : char* listfiles = (char*) m_concat( (char*)char_directory, (char*)"\\*" ); 92 : listfiles = (char*) m_concat( (char*)listfiles, (char*)char_attr ); 93 : DEBUG( (char *)"get_files", "listfiles %s\r\n", listfiles ); 94 : this->get_files( (char*) listfiles, &dummy_filenum ); 95 : } 96 : 97 : } 98 : } 99 : while ( FindNextFile(hFind, &ffd ) != 0); 100 : 101 : FindClose(hFind); 102 : 103 : *file_num = get_strings_number () ; 104 : 105 : return get_strings(); 106 :}