在SDK中,获得一个文件大小或长度的API函数是多少?

catclaw 2003-09-23 01:23:34
在SDK中,获得一个文件大小或长度的API函数是多少,帮忙的各位大哥的麻烦您把后面的参数也写上,谢谢!
...全文
513 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
fbmsf 2003-09-24
  • 打赏
  • 举报
回复
顺便还可以得到其他信息,多好。
fbmsf 2003-09-24
  • 打赏
  • 举报
回复
我晕了,各位,
为什么不用, findclose(FindFirstFile("c:\1.txt",wfd))
wfd.nFileSizeHigh; wfd.nFileSizeLow;
不是大小是什么??
withpointer 2003-09-23
  • 打赏
  • 举报
回复
忘了,最后在return lngSize;前面加上fclose(fp);抱歉!
withpointer 2003-09-23
  • 打赏
  • 举报
回复
同意楼上几位的,但是注意如果用GetFileSize来得到一个文件的大小,在此之前一定要用CreateFile打开文件,这是WIN32的方法

还有一种就是标准C函数方法,先用fopen打开文件,然后用fseek将文件的指针放到文件的结尾处,最后使用ftell得到当前的指针位置(既文件的大小);
具体代码见下,写的匆忙见笑了!
#include <stdio.h>
long cGetFileSize (const char *FileName)
{
//返回-1为失败
long lngSize;
FILE *fp = fopen(FileName,"r");
if (fp == NULL) return -1;

if (fseek(fp,SEEK_END,0) !=0) return -1;
lngSize = ftell(fp);
return lngSize;
}
xiaohedou 2003-09-23
  • 打赏
  • 举报
回复
看了!
stavck 2003-09-23
  • 打赏
  • 举报
回复
一个例子:
struct _stat buf;
int result;
CString strCreateTime;
CString strModTime;
CString strLen;
/* Get data associated with "stat.c": */
result = _stat( strFile.GetBuffer(1), &buf );

/* Check if statistics are valid: */
if( result != 0 )
{
CString strError;
strError.Format(_T("取得文件信息时错误,文件(%s)"), strFile);
return;
}
else
{
strLen.Format(_T("%ld"), buf.st_size);
strCreateTime.Format(_T("%s"), ctime( &buf.st_ctime));
CTime ctm(buf.st_mtime);

strModTime.Format(_T("%04d-%02d-%02d %02d:%02d:%02d"), ctm.GetYear(), ctm.GetMonth(), ctm.GetDay(), ctm.GetHour(), ctm.GetMinute(), ctm.GetSecond());

}
FAICHEN 2003-09-23
  • 打赏
  • 举报
回复
createfile
readfile
program2100 2003-09-23
  • 打赏
  • 举报
回复
DWORD GetFileSize(
HANDLE hFile, // handle of file to get size of
LPDWORD lpFileSizeHigh
// pointer to high-order word for file size
);
不过我记得C语言下也能得到,具体函数在MSDN里找
wuxfBrave 2003-09-23
  • 打赏
  • 举报
回复
HANDLE CreateFile(
LPCTSTR lpFileName,
DWORD dwDesiredAccess,
DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile
);

DWORD GetFileSize(
HANDLE hFile,
LPDWORD lpFileSizeHigh
);

一个函数搞不定,先用CreateFile打开文件,然后再取得大小参数的含义请查看MSDN
李马 2003-09-23
  • 打赏
  • 举报
回复
DWORD GetFileSize(
HANDLE hFile, // handle of file to get size of
LPDWORD lpFileSizeHigh
// pointer to high-order word for file size
);
Parameters
hFile
Specifies an open handle of the file whose size is being returned. The handle must have been created with either GENERIC_READ or GENERIC_WRITE access to the file.
lpFileSizeHigh
Pointer to the variable where the high-order word of the file size is returned. This parameter can be NULL if the application does not require the high-order word.
Return Values
If the function succeeds, the return value is the low-order doubleword of the file size, and, if lpFileSizeHigh is non-NULL, the function puts the high-order doubleword of the file size into the variable pointed to by that parameter.

If the function fails and lpFileSizeHigh is NULL, the return value is 0xFFFFFFFF. To get extended error information, call GetLastError.

If the function fails and lpFileSizeHigh is non-NULL, the return value is 0xFFFFFFFF and GetLastError will return a value other than NO_ERROR.
xfxfxf 2003-09-23
  • 打赏
  • 举报
回复
GetFileSize

16,551

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC相关问题讨论
社区管理员
  • 基础类社区
  • Creator Browser
  • encoderlee
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

        VC/MFC社区版块或许是CSDN最“古老”的版块了,记忆之中,与CSDN的年龄几乎差不多。随着时间的推移,MFC技术渐渐的偏离了开发主流,若干年之后的今天,当我们面对着微软的这个经典之笔,内心充满着敬意,那些曾经的记忆,可以说代表着二十年前曾经的辉煌……
        向经典致敬,或许是老一代程序员内心里面难以释怀的感受。互联网大行其道的今天,我们期待着MFC技术能够恢复其曾经的辉煌,或许这个期待会永远成为一种“梦想”,或许一切皆有可能……
        我们希望这个版块可以很好的适配Web时代,期待更好的互联网技术能够使得MFC技术框架得以重现活力,……

试试用AI创作助手写篇文章吧