Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Visual Basic
  4. Searching for files DateModified value

Searching for files DateModified value

Scheduled Pinned Locked Moved Visual Basic
algorithmsquestion
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • G Offline
    G Offline
    glaidler
    wrote on last edited by
    #1

    Hi, I want to write a function that will search any given folder and all its' subfolders and return any files that have a date modified later than a certain date. Looking at System.IO Namespace, but can't find anything. Any ideas? Graham

    C Richard DeemingR 2 Replies Last reply
    0
    • G glaidler

      Hi, I want to write a function that will search any given folder and all its' subfolders and return any files that have a date modified later than a certain date. Looking at System.IO Namespace, but can't find anything. Any ideas? Graham

      C Offline
      C Offline
      chris foote
      wrote on last edited by
      #2

      look for the fSO object Dim fso As New FileSystemObject, fil As File Set fil = fso.GetFile("c:\detlog.txt") ' Get a File object to query. Debug.Print "File last modified: "; fil.DateLastModified ' Print info

      G 1 Reply Last reply
      0
      • C chris foote

        look for the fSO object Dim fso As New FileSystemObject, fil As File Set fil = fso.GetFile("c:\detlog.txt") ' Get a File object to query. Debug.Print "File last modified: "; fil.DateLastModified ' Print info

        G Offline
        G Offline
        glaidler
        wrote on last edited by
        #3

        Thanks for this Chris, but I'm using vb.net and want to keep it as ".net" as possible. Instead of searching, I'm now using the system.io.fileinfo class and iterating through the files and examining their attributes. Graham

        1 Reply Last reply
        0
        • G glaidler

          Hi, I want to write a function that will search any given folder and all its' subfolders and return any files that have a date modified later than a certain date. Looking at System.IO Namespace, but can't find anything. Any ideas? Graham

          Richard DeemingR Offline
          Richard DeemingR Offline
          Richard Deeming
          wrote on last edited by
          #4

          Both the FileInfo and DirectoryInfo classes inherit from FileSystemInfo, which has the properties you need. For example, LastWriteTime is the modified date/time. Just off the top of my head:

          Imports System.IO
          Imports System.Collections

          ...

          Public Shared Function Search(ByVal folder As String, ByVal minDate As Date) As FileInfo()
          Dim files As New ArrayList()
          Dim folderEntry As New DirectoryInfo(folder)
          SearchInternal(folderEntry, files, minDate)
          Return DirectCast(files.ToArray(GetType(FileInfo)), FileInfo())
          End Function

          Private Shared Sub SearchInternal(ByVal folder As DirectoryInfo, ByVal files As ArrayList, ByVal minDate As Date)
          If folder.Exists Then
          ' List the files in the current directory
          Dim file As FileInfo
          For Each file In folder.GetFiles()
          If file.LastWriteTime > minDate Then
          files.Add(file)
          End If
          Next

              ' Search the subdirectories
              Dim subfolder As DirectoryInfo
              For Each subfolder In folder.GetDirectories()
                  SearchInternal(subfolder, files, minDate)
              Next
          End If
          

          End Sub


          "These people looked deep within my soul and assigned me a number based on the order in which I joined." - Homer

          "These people looked deep within my soul and assigned me a number based on the order in which I joined" - Homer

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups