教导
创建如下 C 脚本作为项目函数。参数值“FileName”是一个带有要搜索文件的路径和文件细节的字符串。该函数的返回值包含找到的文件名。
示例
File_Search("C:DirectoryFile*.*");
项目函数清单
==================
#include "apdefap.h"
LPSTR File_Search(char* FileName)
{
typedef struct _FILETIME {
DWORD dwLowDateTime;
DWORD dwHighDateTime;
} FILETIME;
typedef FILETIME *LPFILETIME;
typedef struct _WIN32_FIND_DATA {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD dwReserved0;
DWORD dwReserved1;
TCHAR cFileName[MAX_PATH];
TCHAR cAlternateFileName[14];
} WIN32_FIND_DATA;
typedef WIN32_FIND_DATA *LPWIN32_FIND_DATA;
#pragma code ("kernel32.dll")
HANDLE FindFirstFileA(LPCTSTR lpFileName,LPWIN32_FIND_DATA lpFindFileData);
BOOL FindClose(HANDLE hFindFile);
#pragma code()
HANDLE handle;
WIN32_FIND_DATA* filedata;
// 为文件数据分配存储空间
filedata = SysMalloc(sizeof(WIN32_FIND_DATA));
handle =FindFirstFileA(FileName, filedata);
// 控制输出到诊断窗口
printf("Searched file: %srn", FileName);
printf("Handle:%drn",handle);
printf("FileName:%srn",filedata->cFileName);
// 返回找到的第一个文件名并关闭句柄
FindClose(handle);
return filedata->cFileName;
}
关键字
数据操作,数据访问
原创文章,作者:ximenziask,如若转载,请注明出处:https://www.zhaoplc.com/plc334714.html