说三道四技术文摘-感悟人生的经典句子
说三道四 > 文档快照

读取档案的建立时间及存取时间 -VB资料

HTML文档下载 WORD文档下载 PDF文档下载
读取档案的建立时间及存取时间 -VB资料
想要进一步读取档案的相关资讯, 必须先呼叫 API 函数的 OpenFile 取得档案的
Handle, 然後再利用 Handle 呼叫 GetFileInformationByHandle 读取档案的相关
资讯, 而在读取的档案相关资讯中便含有档案建立、修改、及存取时间, 程式执
行过程如下:(假设想读取的档案是"c:\autoexec.bat")

 
Public Const OFS_MAXPATHNAME = 128
Public Const OF_READ = &H0
Type OFSTRUCT
cBytes As Byte
fFixedDisk As Byte
nErrCode As Integer
Reserved1 As Integer
Reserved2 As Integer
szPathName(OFS_MAXPATHNAME) As Byte
End Type

Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Type FileTime
dwLowDateTime As Long
dwHighDateTime As Long
End Type


Type BY_HANDLE_FILE_INFORMATION
dwFileAttributes As Long
ftCreationTime As FileTime
ftLastAccessTime As FileTime
ftLastWriteTime As FileTime
dwVolumeSerialNumber As Long
nFileSizeHigh As Long
nFileSizeLow As Long
nNumberOfLinks As Long
nFileIndexHigh As Long
nFileIndexLow As Long
End Type

Type TIME_ZONE_INFORMATION
bias As Long
StandardName(32) As Integer
StandardDate As SYSTEMTIME
StandardBias As Long
DaylightName(32) As Integer
DaylightDate As SYSTEMTIME
DaylightBias As Long
End Type


Declare Function GetTimeZoneInformation Lib "kernel32" _
(lpTimeZoneInformation As TIME_ZONE_INFORMATION) As Long
Declare Function OpenFile Lib "kernel32" (ByVal lpFileName As String, _
lpReOpenBuff As OFSTRUCT, ByVal wStyle As Long) As Long
Declare Function GetFileInformationByHandle Lib "kernel32" (ByVal hFile As _
Long, lpFileInformation As BY_HANDLE_FILE_INFORMATION) As Long
Declare Function CloseHandle Lib "kernel32" (ByVal hObject As Long) As Long
Declare Function FileTimeToSystemTime Lib "kernel32" (lpFileTime As _
FileTime, lpSystemTime As SYSTEMTIME) As Long

Dim FileHandle As Long
Dim FileInfo As BY_HANDLE_FILE_INFORMATION
Dim lpReOpenBuff As OFSTRUCT, ft As SYSTEMTIME
Dim tZone As TIME_ZONE_INFORMATION

Dim dtCreate As Date ' 建立时间
Dim dtAccess As Date ' 存取日期
Dim dtWrite As Date ' 修改时间
Dim bias As Long

' 先取得 autoexec.bat 的 File Handle
FileHandle = OpenFile("c:\autoexec.bat", lpReOpenBuff, OF_READ)
' 利用 File Handle 读取档案资讯
Call GetFileInformationByHandle(FileHandle, FileInfo)
Call CloseHandle(FileHandle)
' 读取 Time Zone 资讯, 因为上一步骤的档案时间是「格林威治」时间
Call GetTimeZoneInformation(tZone)
bias = tZone.bias ' 时间差, 以「分」为单位
Call FileTimeToSystemTime(FileInfo.ftCreationTime, ft) ' 转换时间资料结构
dtCreate = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + ;
TimeSerial(ft.wHour, ft.wMinute - bias, ft.wSecond)
Call FileTimeToSystemTime(FileInfo.ftLastAccessTime, ft)
dtAccess = DateSerial(ft.wYear, ft.wMonth, ft.wDay) + ;
TimeSerial(ft.wHour, ft.wMinute - bias,ft.wSecond)
Call FileTimeToSystemTime(FileInfo.ftLastWriteTime, ft)
dtWrite = DateSerial(ft.wYear, ft.wMonth, ft.wDay) +
TimeSerial(ft.wHour, ft.wMinute - bias,ft.wSecond)

'执行以上程式所得到的 dtCreate、dtWrite、及 dtAccess 变数, 即分别为档案
'建立、修改、及存取时间。

美的+阿里,“云端”战略第一把火是智慧家居 对产业互联网战略的战术思考——争夺企业信息入口的战争 加入Cassandra,OpenStack发力DBaaS生态圈 死磕Google Keep,微软正式发布Mac免费版OneNote 《近匠》安管云CTO石磊:降维安全的开放平台 紧急求救!!!!老师布置的作业!!!!不交要挂了??? 请教高手,电脑一开机就开启IE并进入一个色情网站要怎样处理? 如何使用自定义的密码(随意给出一个字符串)对文件或流加密. 参与者有份,请问:我在画椭圆或者线的时候不知道是否鞋子当我写字的时候如何擦除以前画的。 还是求教HTML表格递交确认的问题 为什么我的窗口可以打开,但窗口名在程序中无法使用 不用session,用参数传值,文件转换的小问题,谢谢 Linux+jsp访问SQL2000数据库(windows平台下),需要什么组件,哪儿有下? 有关BCP的问题(在线等) 身边哪些花草是有毒的 想做个12-30V稳压成2.5-5V的电路,这么做 为什么胶体会吸附电性相同的离子电性相同? 胶体微粒吸附的离子为什么不会和胶体中电性相反的离子 为什么超导体的电阻为0?为什么它拥有完全抗磁效应? 当用焊锡焊接铜丝时,为什么用锉刀除去表面层能使焊接 您好:我们产品用的线是7股的 铜线沾上酸性助焊剂后 某导体两端加2V的电压时,通过的电流为0.5A,则 安全防摔玻璃奶瓶哪种好? 韩考虑增加新一代战机项目预算 现为4德防长批评美国监控传闻 称欧美关系将俄总理七小时“安徽印象”澳洲一名男子涉嫌逼迫未婚妻致其死亡接韩考虑增加新一代战机项目预算 现为4浓雾消散阳光回归 抓紧晒太阳山城后天国际观察:摩苏尔总攻开始“伊斯兰国”牟庆霞:官兵“老大姐” 用真情书写河北高速部分地区有团雾 6个辖区内所美丽河北·最美双拥人物事迹巡展重生之梦想庄园明朝二道贩子不修仙咋成魔有女当嫁都市召唤师长空栈道旅游华山三大险旅游梦山水库旅游梦山胜迹旅游恩施土司城旅游
备案号:鲁ICP备13029499号-2 说三道四 www.s3d4.cn 说三道四技术文摘