Results 1 to 4 of 4

Thread: search by file dates

  1. #1

    Thread Starter
    Member
    Join Date
    Jul 2000
    Posts
    37
    Is there any code to use in a VB app that can search
    files by date? And display files accessed in the past 5 days?

    Thanks,


  2. #2
    Junior Member
    Join Date
    Sep 1999
    Location
    mousafah,abu-dhabi,UAE
    Posts
    29
    use this code to delete the old files from ur pc

    Code:
    Dim MyFile, MyStamp, DestDrive, DestPath
    MyFile = Dir(DestDrive + DestPath + "\*.txt")'Change Extension 
    Do
    MyStamp = FileDateTime(DestDrive + DestPath + "\" + MyFile) MyStamp = DateValue(Left$(MyStamp, 10))  
    If MyStamp < PurgeResp Then Kill(DestDrive + DestPath + "\" + MyFile)
    MyFile = Dir
    If MyFile = "" Then Exit Do
    Loop
    MsgBox "Selected files purged.", vbOKOnly, "Purge Files"
    of course u must remove the kill statement & put ur code
    Ahmed Walid

  3. #3
    New Member
    Join Date
    Feb 2001
    Posts
    4

    Search Files By Date

    Did you come up with a solution for returning a list of files that were last updated in a specified date range? I am looking to do the same thing and would like to know if there are API's that could retrieve this information

  4. #4
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    '**********************   bas module code
    'for this example you need 1 listbox List1 and 1 command button Command1
    
    'Get files in folder as per a date you supply
    
    
    Option Explicit
    
    Public myFileList()
     
    Public Type FileInfoType
        FileName As String
        FileDate As Date
    End Type
    
    Public Function GetRecentFileList(ByVal Path As String, sDays As Integer) As FileInfoType()
    
        Dim sList() As FileInfoType
        Dim CurFile As String
        Dim CurFileDate As Date
        Dim IdxFile As Integer
        Dim sNow As Date
        
        'if the path is missing a \ then add it to the path
        If Right(Path, 1) <> "\" Then Path = Path & "\"
        'get the current file
           CurFile = Dir(Path & "*.*")
        
        'loop
        Do While CurFile <> ""
        
          CurFileDate = FileDateTime(Path & CurFile)    'file date
          sNow = Now                                    'today's date
          
          If DateDiff("d", CurFileDate, sNow) <= sDays Then
          ReDim Preserve sList(IdxFile) As FileInfoType     'based on filecount of items in criteria
                With sList(IdxFile)                         'gather the date and time information
                   .FileName = CurFile
                   .FileDate = CurFileDate
              End With
             '   Form1.List1.AddItem CurFile & sList(IdxFile).FileDate & _
                "  FileTime:  " & sList(IdxFile).Filetime
          
          ReDim Preserve myFileList(IdxFile)    'store the files and dates and times in an array
               myFileList(IdxFile) = "File Name:      " & sList(IdxFile).FileName _
               & "        FileTime:        " & sList(IdxFile).FileDate
                
                  IdxFile = IdxFile + 1    'increment the counter
          End If
           CurFile = Dir()   'next file
         
         Loop
        
        GetRecentFileList = sList()
    
    End Function
    
    
    '**********************     Form Code
    'change C:\my documents for your directory
    'change 5 to reflect the number of days you need
    
    Option Explicit
    
    Private Sub Command1_Click()
    'declare an array of FileInfoType to hold the filelisting
    Dim sFileList() As FileInfoType, x As Integer
    
        sFileList = GetRecentFileList("c:\my documents", 5)  'get files from last 5 days
        For x = LBound(myFileList) To UBound(myFileList)
          List1.AddItem myFileList(x)
        Next x
        
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width