在实际业务中,Creo对文件操作时需要对制定的文件夹中的文件进行循环遍历,查找到符合要求的文件,以便进行操作
ProPath *file_list, *dir_list; //文件名和路径名称保存指针
ProName w_nm; //路径
ProStringToWstring(w_nm, (char*)("C:\\PTC\\Creo 2.0\\Common Files\\M130\\formats"));
ProArrayAlloc(0, sizeof(ProPath), 1, (ProArray*)&file_list);//分配数组
ProArrayAlloc(0, sizeof(ProPath), 1, (ProArray*)&dir_list); //分配数组
ProFilesList(w_nm, _T("*.frm"), PRO_FILE_LIST_ALL, &file_list, &dir_list);//对路径下的frm格式文件进行过滤
CString str ;int count = 0 ;
ProArraySizeGet((ProArray*)file_list,&count);
str.Format(_T("一共有%d的文件"),count);
for (int i = 0;i
{
AfxMessageBox(file_list[i]);
//针对查找符合要求的对象进行业务操作
}
ProError ProFilesList (
ProPath directory_path
/* (In)
The directory in which to look for the files to be listed. If this is NULL, the files from the current directory will be listed.
*/
ProLine filter
/* (In)
The user-supplied filter string for file extensions. Each filter must be separated by a comma. For example, "*.prt,*.txt" (converted to a wide-character string). Each individual element in the filter must be less than PRO_NAME_SIZE characters.
*/
ProFileListOpt listing_option
/* (In)
Specifies whether all versions or only the latest versions are being requested, and whether or not the list should be sorted alphabetically. Note: Passing any of _INST options in Wildfire 4.0 M100 and earlier will have the same effect as passing PRO_FILE_LIST_LATEST.
*/
ProPath** p_file_name_array
/* (Out)
The array of files found. You must preallocate this array using ProArrayAlloc(); if you reuse the array, new elements will be appended to the existing elements unless you reset the array size to 0 with ProArraySizeSet.
*/
ProPath** p_subdir_name_array
/* (Out)
The array of all subdirectories found, regardless of whether they match the filter. You must preallocate this array using ProArrayAlloc(); if you reuse the array, new elements will be appended to the existing elements unless you reset the array size to 0 with ProArraySizeSet.
*/
)