PC Review


Reply
Thread Tools Rate Thread

DirectoryInfo Getfiles - only for one file

 
 
jobs
Guest
Posts: n/a
 
      26th Feb 2007
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.

 
Reply With Quote
 
 
 
 
SAL
Guest
Posts: n/a
 
      26th Feb 2007
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

"jobs" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Q: DirectoryInfo.GetFiles Martin Arvidsson, Visual Systems AB Microsoft C# .NET 1 17th Apr 2007 04:07 PM
Directory.GetFiles() / DirectoryInfo.GetFiles() on a remote server =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?= Microsoft ASP .NET 2 24th Mar 2007 06:59 PM
DirectoryInfo.GetFiles returns only the first file name? rosty Microsoft Dot NET Framework 3 10th Feb 2004 11:06 AM
DirectoryInfo.GetFiles() Pluto Microsoft C# .NET 4 9th Oct 2003 03:49 AM
DirectoryInfo.GetFiles Paul K Microsoft Dot NET Framework 5 31st Jul 2003 11:05 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:19 PM.