Search code examples
vb.netdatagridviewsystem.io.directory

Get date creation or date modified of a file?


I want to get creation date, last modify date other details relating to files, and adding them to a datagridview. Currently I am getting the file information by using directory.getfiles. Here's what i got so far:

Dim paths() As String = IO.Directory.GetFiles("mypath")

For Each sFile As String In paths
    Dim fileNameOnly As String = Path.GetFileNameWithoutExtension(sFile)
    gridview.Rows.Add(fileNameOnly)
Next

Solution

  • This is how I would grab both the created date, and the last write time.

    For each sfile as datetime.tostring in paths
         Dim fileCreatedDate As DateTime = File.GetCreationTime(paths)
         Dim fileLastWrite as DateTime = File.GetLastWriteTime(path)
    Next
    

    To get files inbetween a date, try this..

    Dim [date] As DateTime = firstdatevariable
    While [date] <= seconddatevariable
         'add dates that are inbetween them
    End While