DirectoryInfo Getfiles - only for one file

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.
 
S

SAL

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top