Office中國(guó)論壇/Access中國(guó)論壇

 找回密碼
 注冊(cè)

QQ登錄

只需一步,快速開(kāi)始

返回列表 發(fā)新帖
查看: 1255|回復(fù): 5
打印 上一主題 下一主題

[Access本身] 如何取得外部文件的日期

[復(fù)制鏈接]
跳轉(zhuǎn)到指定樓層
1#
發(fā)表于 2009-12-12 16:51:54 | 只看該作者 回帖獎(jiǎng)勵(lì) |倒序?yàn)g覽 |閱讀模式
本帖最后由 yaozi 于 2009-12-17 08:54 編輯

請(qǐng)教一下,如何取得外部文件(不是數(shù)據(jù)庫(kù)本身)的創(chuàng)建日期或修改日期,謝謝。
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享分享 分享淘帖 訂閱訂閱
2#
發(fā)表于 2009-12-12 17:20:10 | 只看該作者
Option Compare Database

'»ñÈ¡ÎļþÐÅÏ¢µÄGetFileInfoº¯Êý
Type FileInfo
    FileName As String   'Ãû×Ö
    ShortName As String
    Type As String    'ÀàÐÍ
        Size As Long
        DateCreate As Date
        DateLastModified As Date '
        DateLastAccessed As Date
        Attributes As String
    End Type

    '===============================================================================
    '-º¯ÊýÃû³Æ:     GetFileInfo
    '-¹¦ÄÜÃèÊö:     »ñÈ¡ÎļþÐÅÏ¢
    '-ÊäÈë²ÎÊý˵Ã÷: ²ÎÊý1: ±ØÑ¡ strFile As String Îļþ·¾¶ºÍÃû³Æ
    '-·µ»Ø²ÎÊý˵Ã÷: ·µ»ØÎļþÃû³Æ£¬ÀàÐÍ£¬´óС£¬¸üÐÂÈÕÆÚµÈ
    '-ʹÓÃÓ﷨ʾÀý: Msgbox GetFileInfo("C:\Abc.txt").Size
    '-ÒýÓÃ:Microsoft Scripting Runtime
    '===============================================================================
Function GetFileInfo(strFile As String) As FileInfo
    On Error Resume Next
    Dim fsoSys As New Scripting.FileSystemObject
    Dim fsoFile As File
    Dim strstrastr As String

    Set fsoFile = fsoSys.GetFile(strFile)
    With GetFileInfo
        .FileName = fsoFile.Name
        .ShortName = fsoFile.ShortName
        .Type = fsoFile.Type
        .Size = fsoFile.Size / 1000
        .DateCreate = fsoFile.DateCreated
        .DateLastModified = fsoFile.DateLastModified
        .DateLastAccessed = fsoFile.DateLastAccessed

        If fsoFile.Attributes And Archive Then
            strAstr = strAstr & "³£¹æ "
        End If
        If fsoFile.Attributes And ReadOnly Then
            strAstr = strAstr & "Ö»¶Á "
        End If
        If fsoFile.Attributes And Hidden Then
            strAstr = strAstr & "Òþ²Ø "
        End If
'        If fsoFile.Attributes And System Then 'ÕâÒ»¾äÓÐÎÊÌ⣬Ìáʾsystem䶨Òå
        If fsoFile.Attributes And 4 Then
            strAstr = strAstr & "ϵͳ "
        End If
        If fsoFile.Attributes And Compressed Then
            strAstr = strAstr & "ѹËõ "
        End If
        .Attributes = strAstr
    End With

    Set fsoSys = Nothing
    Set fsoFile = Nothing

End Function
3#
發(fā)表于 2009-12-12 17:21:01 | 只看該作者
不好意思,剛才的代碼有亂碼,看看這個(gè)。
Option Compare Database

'獲取文件信息的GetFileInfo函數(shù)
Type FileInfo
    FileName As String   '名字
    ShortName As String
    Type As String    '類型
        Size As Long
        DateCreate As Date
        DateLastModified As Date '
        DateLastAccessed As Date
        Attributes As String
    End Type

    '===============================================================================
    '-函數(shù)名稱:     GetFileInfo
    '-功能描述:     獲取文件信息
    '-輸入?yún)?shù)說(shuō)明: 參數(shù)1: 必選 strFile As String 文件路徑和名稱
    '-返回參數(shù)說(shuō)明: 返回文件名稱,類型,大小,更新日期等
    '-使用語(yǔ)法示例: Msgbox GetFileInfo("C:\Abc.txt").Size
    '-引用:Microsoft Scripting Runtime
    '===============================================================================
Function GetFileInfo(strFile As String) As FileInfo
    On Error Resume Next
    Dim fsoSys As New Scripting.FileSystemObject
    Dim fsoFile As File
    Dim strstrastr As String

    Set fsoFile = fsoSys.GetFile(strFile)
    With GetFileInfo
        .FileName = fsoFile.Name
        .ShortName = fsoFile.ShortName
        .Type = fsoFile.Type
        .Size = fsoFile.Size / 1000
        .DateCreate = fsoFile.DateCreated
        .DateLastModified = fsoFile.DateLastModified
        .DateLastAccessed = fsoFile.DateLastAccessed

        If fsoFile.Attributes And Archive Then
            strAstr = strAstr & "常規(guī) "
        End If
        If fsoFile.Attributes And ReadOnly Then
            strAstr = strAstr & "只讀 "
        End If
        If fsoFile.Attributes And Hidden Then
            strAstr = strAstr & "隱藏 "
        End If
'        If fsoFile.Attributes And System Then '這一句有問(wèn)題,提示system未定義
        If fsoFile.Attributes And 4 Then
            strAstr = strAstr & "系統(tǒng) "
        End If
        If fsoFile.Attributes And Compressed Then
            strAstr = strAstr & "壓縮 "
        End If
        .Attributes = strAstr
    End With

    Set fsoSys = Nothing
    Set fsoFile = Nothing

End Function
4#
發(fā)表于 2009-12-12 17:21:26 | 只看該作者
Option Compare Database

'»ñÈ¡ÎļþÐÅÏ¢µÄGetFileInfoº¯Êý
Type FileInfo
    FileName As String   'Ãû×Ö
    ShortName As String
    Type As String    'ÀàÐÍ
        Size As Long
        DateCreate As Date
        DateLastModified As Date '
        DateLastAccessed As Date
        Attributes As String
    End Type

    '===============================================================================
    '-º¯ÊýÃû³Æ:     GetFileInfo
    '-¹¦ÄÜÃèÊö:     »ñÈ¡ÎļþÐÅÏ¢
    '-ÊäÈë²ÎÊý˵Ã÷: ²ÎÊý1: ±ØÑ¡ strFile As String Îļþ·¾¶ºÍÃû³Æ
    '-·µ»Ø²ÎÊý˵Ã÷: ·µ»ØÎļþÃû³Æ£¬ÀàÐÍ£¬´óС£¬¸üÐÂÈÕÆÚµÈ
    '-ʹÓÃÓ﷨ʾÀý: Msgbox GetFileInfo("C:\Abc.txt").Size
    '-ÒýÓÃ:Microsoft Scripting Runtime
    '===============================================================================
Function GetFileInfo(strFile As String) As FileInfo
    On Error Resume Next
    Dim fsoSys As New Scripting.FileSystemObject
    Dim fsoFile As File
    Dim strstrastr As String

    Set fsoFile = fsoSys.GetFile(strFile)
    With GetFileInfo
        .FileName = fsoFile.Name
        .ShortName = fsoFile.ShortName
        .Type = fsoFile.Type
        .Size = fsoFile.Size / 1000
        .DateCreate = fsoFile.DateCreated
        .DateLastModified = fsoFile.DateLastModified
        .DateLastAccessed = fsoFile.DateLastAccessed

        If fsoFile.Attributes And Archive Then
            strAstr = strAstr & "³£¹æ "
        End If
        If fsoFile.Attributes And ReadOnly Then
            strAstr = strAstr & "Ö»¶Á "
        End If
        If fsoFile.Attributes And Hidden Then
            strAstr = strAstr & "Òþ²Ø "
        End If
'        If fsoFile.Attributes And System Then 'ÕâÒ»¾äÓÐÎÊÌ⣬Ìáʾsystem䶨Òå
        If fsoFile.Attributes And 4 Then
            strAstr = strAstr & "ϵͳ "
        End If
        If fsoFile.Attributes And Compressed Then
            strAstr = strAstr & "ѹËõ "
        End If
        .Attributes = strAstr
    End With

    Set fsoSys = Nothing
    Set fsoFile = Nothing

End Function
5#
 樓主| 發(fā)表于 2009-12-17 08:35:01 | 只看該作者
好像不行吧,只出現(xiàn)一些數(shù)字。
6#
 樓主| 發(fā)表于 2009-12-17 08:52:02 | 只看該作者
不好意思,剛才的代碼有亂碼,看看這個(gè)。
Option Compare Database

'獲取文件信息的GetFileInfo函數(shù)
Type FileInfo
    FileName As String   '名字
    ShortName As String
    Type As String    '類型
...
chaojianan 發(fā)表于 2009-12-12 17:21

謝謝,成功了。剛才弄錯(cuò)了
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則

QQ|站長(zhǎng)郵箱|小黑屋|手機(jī)版|Office中國(guó)/Access中國(guó) ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2024-10-23 08:30 , Processed in 0.097066 second(s), 29 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回復(fù) 返回頂部 返回列表