请问GetFileSize()的用法?

sjd163 2002-08-14 07:25:18
请问GetFileSize()的用法?
...全文
469 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
dycdyc123 2002-08-14
  • 打赏
  • 举报
回复
MSDN
多的是

lngHandle = CreateFile("C:\KPD-Team\test.kpd", GENERIC_WRITE, FILE_SHARE_READ Or

FILE_SHARE_WRITE

这个恐怕是错误的喔

C:\\KPD-Team\\test.kpd

mikesome 2002-08-14
  • 打赏
  • 举报
回复
实例参考
lngHandle = CreateFile("C:\KPD-Team\test.kpd", GENERIC_WRITE, FILE_SHARE_READ Or

FILE_SHARE_WRITE, ByVal 0&, OPEN_EXISTING, 0, 0)
'Get the file's size
GetFileSize(lngHandle, lngLong);

Thumb168 2002-08-14
  • 打赏
  • 举报
回复
朋友好象忘记给多少分了。这样可不好。呵呵
Thumb168 2002-08-14
  • 打赏
  • 举报
回复
DWORD GetFileSize(

HANDLE hFile, // handle of file to get size of
LPDWORD lpFileSizeHigh // address of 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

Points 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.

Remarks

You cannot use the GetFileSize function with a handle of a nonseeking device such as a pipe or a communications device. To determine the file type for hFile, use the GetFileType function.
The GetFileSize function obtains the uncompressed size of a file. Use the GetCompressedFileSize function to obtain the compressed size of a file.
Note that if the return value is 0xFFFFFFFF and lpFileSizeHigh is non-NULL, an application must call GetLastError to determine whether the function has succeeded or failed. The following sample code illustrates this point:

//
// Case One: calling the function with
// lpFileSizeHigh == NULL

// Try to obtain hFile's size
dwSize = GetFileSize (hFile, NULL) ;

// If we failed ...
if (dwSize == 0xFFFFFFFF) {

// Obtain the error code.
dwError = GetLastError() ;

// Deal with that failure.
.
.
.

} // End of error handler


//
// Case Two: calling the function with
// lpFileSizeHigh != NULL

// Try to obtain hFile's huge size.

dwSizeLow = GetFileSize (hFile, & dwSizeHigh) ;

// If we failed ...
if (dwSizeLow == 0xFFFFFFFF
&&
(dwError = GetLastError()) != NO_ERROR ){

// Deal with that failure.
.
.
.

} // End of error handler.
mikesome 2002-08-14
  • 打赏
  • 举报
回复
kernel32的文件处理API函数
声明:Declare Function GetFileSize Lib "kernel32" Alias "GetFileSize" (ByVal hFile As Long, lpFileSizeHigh As Long) As Long
参数说明:
Long,返回文件长度。& HFFFFFFFF表示出错。注意如lpFileSizeHigh不为NULL,且结果为& HFFFFFFFF,那么必须调用GetLastError,判断是否实际发生了一个错误,因为这是一个有效的结果hFile ---------- Long,文件的句柄lpFileSizeHigh - Long,指定一个长整数,用于装载一个64位文件长度的头32位。如这个长度没有超过2^32字节,则该参数可以设为NULL(变成ByVal)
1.引言 几乎所有的Web项目开发都需要客户端验证,尤其是JavaScript的使用,JS结合Html和CSS占据了网页展现市场,不管采用什么技术我们在网页看到的东西最终生成都是这些代码所表示含义。 Web应用如此广泛,其中客户端与服务端交互时所消耗的资源及响应时间,频繁的刷新页面使得人机交互体验极为不好,而对每个页面使用客户端处理技术无疑又加大项目开发周期,脚本调试及修改维护的工作量将占用大量的开发时间,验证控件须对每个控件的元素进行设置且会对页面整体的布局带来影响,占据着页面布局空间的位置,综合考虑及项目整体风格的统一等多种因素中,总得有个折中的考虑。ChkInputs.js应运而生,使用它不需要编写多少代码,只需对验证元素简单配置一下即可,使用方便,也不会影响页面的布局,并可以精确判断客户端输入框的长度、必填、数据类型(整数型、浮点型、字母型、数字字母混合型)和下拉框等,及对需要验证的控件分组验证等。同时提供许多常用的公共函数如类似C#中Trim()方法等。 使用ChkInputs.js,会将光标定位到验证不通过的控件上,若控件上有文本同时将其文本选中高亮度显示,不会刷新页面,只有当所有验证通过时才会将结果提交到后台处理,可以使用鼠标或纯键盘及相结合的方式来操作。 2.ChkInputs.js的使用: ChkInputs.js的使用极为方便,你可以直接将自定义属性像这样添加在Web页面, 也可以在后台代码里这样添加,如在.net下.aspx.cs代码里这样写: this.TextBox1.Attributes.Add("chinese", "测试输入框");//控件名称 this.TextBox1.Attributes.Add("maxsize", "6");//控件接受的字符长度大小 this.TextBox1.Attributes.Add("nullable", "no");//不可为空,默认可为空 this.TextBox1.Attributes.Add("datatype", "number");//控件数据类型 两者代码是一样的,不过一般在后台代码(.cs)写好写,因为这样写有利于项目的维护修改。当页面的控件元素都设置好时,客户端代码通常只需这样写即可: 首先在页面head区域内定义一个这样的JS函数 <script language="javascript"> //例一,全部验证,比较常用,基本满足一般所有的验证功能 function CheckInfoAll() { return verifyAll(document.getElementById("form1")); } FileSize(…)可直接取得待上传文件的字节大小,但也有限制就是客户端浏览须启用ActiveX插件,若没有启用时,会提示用户按步骤设置。CancelClientEvent()是使用事件冒泡阻止了事件的继续执行,同时设置返回值,最终成功阻止事件的继续往后执行,当在客户端触发一要回发的按钮事件是,想在程序里结束让其继续执行时,以往则不是很好处理,如Enter键,这里此方法则大显用武之地。 附有ChkInputs.js完整的源代码及实例代码。

13,825

社区成员

发帖
与我相关
我的任务
社区描述
C++ Builder相关内容讨论区
社区管理员
  • 基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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