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. Filename of LastWriteTime

Filename of LastWriteTime

Scheduled Pinned Locked Moved Visual Basic
question
2 Posts 2 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.
  • V Offline
    V Offline
    VK Cadec
    wrote on last edited by
    #1

    Hi - I am trying to get the filename of the last written file in a directory. Any ideas why this code doesn''t work? Dim _direct As DirectoryInfo Dim _strLastfileName, _strDirectpath As String _strDirectpath = txtExportPath.Text ' path to directory _direct = New DirectoryInfo(_strDirectpath) _strLastfileName = New FileInfo(_direct.LastWriteTime).Name.ToString

    D 1 Reply Last reply
    0
    • V VK Cadec

      Hi - I am trying to get the filename of the last written file in a directory. Any ideas why this code doesn''t work? Dim _direct As DirectoryInfo Dim _strLastfileName, _strDirectpath As String _strDirectpath = txtExportPath.Text ' path to directory _direct = New DirectoryInfo(_strDirectpath) _strLastfileName = New FileInfo(_direct.LastWriteTime).Name.ToString

      D Offline
      D Offline
      Dave Kreskowiak
      wrote on last edited by
      #2

      The only way to know which file was written to last is to get the LastAccess time for every file in the folder, sort the list and get the filename off the top of the sorted list. The LastWriteTime of the Directory is a change in the directory entries for that folder, not the last write to a file in that directory. Also, The FileInfo class constructor takes a filename as a string as an argument. You're supplying a DateTime object (_direct.LastWriteTime) as the argument, which won't work.

      Dave Kreskowiak Microsoft MVP - Visual Basic

      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