如何获得文件长度?
不用API调用,仅用BCB封装的函数无何实现?
[解决办法]
FILE *fp = fopen( "c.dat ", "rb ");
fseek(fp, 0, 2);
int fsize = ftell(fp);
[解决办法]
楼上正解,我帖个详细一点的。
#include <stdio.h>
long filesize(FILE *stream);
int main(void)
{
FILE *stream;
stream = fopen( "MYFILE.TXT ", "w+ ");
fprintf(stream, "This is a test ");
printf( "Filesize of MYFILE.TXT is %ld bytes\n ", filesize(stream));
fclose(stream);
return 0;
}
long filesize(FILE *stream)
{
long curpos, length;
curpos = ftell(stream);
fseek(stream, 0L, SEEK_END);
length = ftell(stream);
fseek(stream, curpos, SEEK_SET);
return length;
}
[解决办法]
使用BCB函数操作如下:
HFILE hFile = FileOpen( "myfile ",fmOpen);
int nFileSize = FileSeek(hFile,0,2); //nFileSize即文件大小(字节)
FileClose(hFile);
[解决办法]
int nFileHandle = FileOpen( "C:\\ccrun\\123.exe ", fmOpenRead);
int nFileLen = FileSeek(nFileHandle, 0, 2);