你好!
我现在正在完成我的数据库作业,现在碰到了一个问题:
我在用纯语言,而不借助于MFC怎样实现---取得一个文件的"大小,路径,上次访问时间,对一个文件的转移,和删除"?
请各位好心人赐教,谢谢!!!!!
我现在正在完成我的数据库作业,现在碰到了一个问题:
我在用纯语言,而不借助于MFC怎样实现---取得一个文件的"大小,路径,上次访问时间,对一个文件的转移,和删除"?
请各位好心人赐教,谢谢!!!!!
DWORD GetFileSize(
HANDLE hFile, // handle of file to get size of
LPDWORD lpFileSizeHigh
// pointer to high-order word for file size
);
路径:
DWORD GetFullPathName(
LPCTSTR lpFileName, // pointer to name of file to find path for
DWORD nBufferLength, // size, in characters, of path buffer
LPTSTR lpBuffer, // pointer to path buffer
LPTSTR *lpFilePart // pointer to filename in path
);
上次访问时间:
BOOL GetFileTime(
HANDLE hFile, // handle to the file
LPFILETIME lpCreationTime, // address of creation time
LPFILETIME lpLastAccessTime, // address of last access time
LPFILETIME lpLastWriteTime // address of last write time
);
对一个文件的转移:
BOOL MoveFile(
LPCTSTR lpExistingFileName, // pointer to the name of the existing file
LPCTSTR lpNewFileName // pointer to the new name for the file
);
删除:
BOOL DeleteFile(
LPCTSTR lpFileName // pointer to name of file to delete
);
要善于利用MSDN。
移动文件:
BOOL MoveFile(
LPCTSTR lpExistingFileName, // pointer to the name of the existing file
LPCTSTR lpNewFileName // pointer to the new name for the file
);删除文件
BOOL DeleteFile(
LPCTSTR lpFileName // pointer to name of file to delete
);
_BY_HANDLE_FILE_INFORMATION FileInfo;
HANDLE hFile = ::CreateFile(strPath, 0, FILE_SHARE_READ, NULL, OPEN_EXISTING,FILE_ATTRIBUTE_NORMAL, NULL);
if(hFile != INVALID_HANDLE_VALUE)
{
GetFileInformationByHandle(hFile, &FileInfo);
CloseHandle(hFile);
}这个里面得到的信息足够你用了:
typedef struct _BY_HANDLE_FILE_INFORMATION {
DWORD dwFileAttributes;
FILETIME ftCreationTime;
FILETIME ftLastAccessTime;
FILETIME ftLastWriteTime;
DWORD dwVolumeSerialNumber;
DWORD nFileSizeHigh;
DWORD nFileSizeLow;
DWORD nNumberOfLinks;
DWORD nFileIndexHigh;
DWORD nFileIndexLow;
} BY_HANDLE_FILE_INFORMATION, *PBY_HANDLE_FILE_INFORMATION, *LPBY_HANDLE_FILE_INFORMATION;删除文件:
SHFILEOPSTRUCT ShDelFile = {0};
ShDelFile.pTo = NULL;
ShDelFile.wFunc = FO_DELETE;
ShDelFile.fFlags = FOF_ALLOWUNDO; //表示不是删除而是移动到回收站
ShDelFile.pFrom = pPathBuf; //要删除的文件路径SHFileOperation(&ShDelFile);
做"纯语言"作业的话,应该用stat, unlink/remove之类