Dirlistbox filename uitbreiden met file datum en tijd

Status
Niet open voor verdere reacties.

Mark Boerkamp

Gebruiker
Lid geworden
13 mrt 2010
Berichten
70
Hoi,

Ik heb een DirListBox waarin de filenaam wordt weergegeven, ik zou graag willen dat daar de datum en tijd bij komt te staan, wat moet ik dan aanpassen ?

Code:
Function DirListBox(fld As Control, Id, row, col, code)
    ' Purpose:    To read the contents of a directory into a ListBox.
    ' Usage:      Create a ListBox. Set its RowSourceType to "DirListBox"
    ' Parameters: The arguments are provided by Access itself.
    ' Notes:      You could read a FileSpec from an underlying form.
    '             Error handling not shown. More than 512 files not handled.
    Dim StrFileName As String
    Static StrFiles(0 To 511) As String ' Array to hold File Names
    Static intCount As Integer          ' Number of Files in list

    Select Case code
        Case 0                          ' Initialize
            DirListBox = True

        Case 1                          ' Open: load file names into array
            DirListBox = Timer
            StrFileName = Dir$("Directory")   ' Read filespec from a form here???
            Do While Len(StrFileName) > 0
                StrFiles(intCount) = StrFileName
                StrFileName = Dir
                intCount = intCount + 1
            Loop

        Case 3                          ' Rows
            DirListBox = intCount

        Case 4                          ' Columns
            DirListBox = 1

        Case 5                          ' Column width in twips
            DirListBox = 1440

        Case 6                          ' Supply data
            DirListBox = StrFiles(row)

    End Select
End Function

Alvast bedankt voor je reactie,

Groeten,

Mark.
 
Hoi Michel, ik zou willen zien de "date/time modified" of "date/time created".

Groeten,
Mark.
 
Met een extra functie moet het kunnen:

Code:
Function FileLastModified(sFullFileName As String) As Date
Dim fso As Object, file As Object, Output As Date
Set fso = CreateObject("Scripting.FileSystemObject")
Set file = fso.GetFile(sFullFileName)
Output = CDate(CDbl(fso.DateLastModified))
FileLastModified = Output
Set fso = Nothing
Set file = Nothing
End Functio

Code:
Function DirListBox(fld As Control, Id, row, col, code)
    ' Purpose:    To read the contents of a directory into a ListBox.
    ' Usage:      Create a ListBox. Set its RowSourceType to "DirListBox"
    ' Parameters: The arguments are provided by Access itself.
    ' Notes:      You could read a FileSpec from an underlying form.
    '             Error handling not shown. More than 512 files not handled.
    Dim StrFileName As String
    Static StrFiles(0 To 511) As String ' Array to hold File Names
    Static intCount As Integer          ' Number of Files in list
    Select Case code
        Case 0                          ' Initialize
            DirListBox = True
        Case 1                          ' Open: load file names into array
            DirListBox = Timer
            StrFileName = Dir$("Directory") [B][COLOR=blue]& " - " & Format(FileLastModified(Dir$("Directory"))[/COLOR][COLOR=blue];"yymmdd")[/COLOR][/B]
            Do While Len(StrFileName) > 0
                StrFiles(intCount) = StrFileName
                StrFileName = Dir
                intCount = intCount + 1
            Loop
        Case 3                          ' Rows
            DirListBox = intCount
        Case 4                          ' Columns
            DirListBox = 1
        Case 5                          ' Column width in twips
            DirListBox = 1440
        Case 6                          ' Supply data
            DirListBox = StrFiles(row)
    End Select
End Function
 
Hoi Michel,

Bedankt voor je oplossing, kun je op deze manier ook meerdere directory's in je listbox laten zien, of meerdere dirlistbox in 1 formulier plaatsen ?

Groeten,
Mark
 
Je kunt de routine denk ik wel aanpassen zodat hij meerdere mappen opslaat. Je moet er dan denk ik een loopje tussenbouwen die steeds om een nieuwe map vraagt. In de routine gebeurt dat met het DIR commando. Dat leest alle (geselecteerde) bestanden uit de actieve map. Om meer mappen te gebruiken, moet je dus DIR naar een andere map leiden, zodat de procedure de nieuwe input kan gebruiken.
 
Status
Niet open voor verdere reacties.
Terug
Bovenaan Onderaan