DirectoryInfo Getfiles - only for one file

  • Thread starter Thread starter jobs
  • Start date Start date
J

jobs

Say I only have a single file I want to get information on. How can I
adapt this code?

Dim dr As DataRow
Dim fi As FileInfo
Dim dir As New DirectoryInfo(filename)
Dim dt As New DataTable
dt.Columns.Add("FileName", GetType(String))
dt.Columns.Add("CeateTime", GetType(String))
dt.Columns.Add("Length", GetType(String))
For Each fi In dir.GetFiles()
dr = dt.NewRow
dr(0) = fi.Name
dr(1) = fi.CreationTime.Date.ToString
dr(2) = fi.Length
dt.Rows.Add(dr)
Next


Also, curious say i wanted to get the first or last file of the
GetFiles?

Thanks.
 
If you need to pass in a search pattern for GetFiles, you might want to use
Directory.GetFiles instead of DirectoryInfo.GetFiles.
Also, I assume you know how to access the first and last element of an
array. The first element will be at index 0 and the last element will be at
Array.GetUpperBound(0)

S
 
Back
Top