lookup text file creation date

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • MrDeej
    New Member
    • Apr 2007
    • 157

    #1

    lookup text file creation date

    Hello!

    I am designing an import module in my access database for text files

    it looks like this
    Code:
    Dim GammeltNavn As String
    Dim NyttNavn As String
    Dim MaskinNavn As String
    Dim fsoFileSearch As FileSearch
    Set fsoFileSearch = Application.FileSearch
    With fsoFileSearch
    
    'Dim NettVerkssøk As New ADODB.Recordset
       ' NettVerkssøk.Open "SELECT * from [tbl atfmaskiner]", CurrentProject.Connection, adOpenDynamic, adLockOptimistic
       ' Do Until NettVerkssøk.EOF
    .NewSearch
    '.LookIn = "\\" & NettVerkssøk!Maskinnavn & "\ATF" & Right(NettVerkssøk!Maskinnavn, 1)
    .LookIn = "C:\ATF4"
    .FileType = msoFileTypeAllFiles
    .SearchSubFolders = False
    MaskinNavn = "Gemba Maskin 4"
    
    
    Dim RSTFRA As New ADODB.Recordset
    Dim RSTTIL As New ADODB.Recordset
    Dim RSTTIL2 As New ADODB.Recordset
    
    If .Execute(msoSortByLastModified) > 0 Then
        'MsgBox .FoundFiles.Count & " fil(er) funnet"
    
        For i = 1 To .FoundFiles.Count
            MsgBox .PropertyTests
            If Right(.FoundFiles(i), 2) = "F6" Then
            GammeltNavn = .FoundFiles(i)
            NyttNavn = Left(GammeltNavn, (Len(GammeltNavn) - 3)) & ".txt"
            Name GammeltNavn As NyttNavn
            
            DoCmd.TransferText acImportFixed, "maskinpåfylling", "tbl maskinpåfylling", NyttNavn, False, ""
            
            Kill NyttNavn

    This works fine but one thing. That is that i need to get the text file's creation date from the file properties.
    Is there any way to do this?
  • janders468
    Recognized Expert New Member
    • Mar 2008
    • 112

    #2
    You can use the FileSystemObjec t to check the creation date. You can get a reference to it by setting a reference to Microsft Scripting Runtime (or you can use the CreateObject method to set a generic Object if you don't want to set a reference). The Function below will return what you want.
    Code:
    Public Function GetCreateDate(Path As String) as Date
        Dim fso As Scripting.FileSystemObject
        Dim fsoFile As Scripting.File
        Set fso = New Scripting.FileSystemObject
        Set fsoFile = fso.GetFile(Path)
        GetCreateDate = fsoFile.DateCreated
    End Function

    Comment

    • MrDeej
      New Member
      • Apr 2007
      • 157

      #3
      Thank you!

      I will look into this by next week :)

      Comment

      • ADezii
        Recognized Expert Expert
        • Apr 2006
        • 8834

        #4
        The simplest method of retrieving a File's Date and Time of Creation or Last Modified Date is to use the intrinsic FileDateTime() Function, as in:
        [CODE=vb]
        Dim varFileStamp

        varFileStamp = FileDateTime("C :\Windows\Syste m32\Wups.dll")

        Debug.Print varFileStamp[/CODE]
        OUTPUT:
        Code:
        7/30/2007 7:18:40 PM
        1. If the File can be modified, you will not want to use this approach, since it will return the Last Modified Date and not the actual Date on which it was Created.
        2. Incorporating this into your existing code should be a simple matter.

        Comment

        Working...