473,545 Members | 2,679 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

DirectoryInfo Getfiles - only for one file

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(f ilename)
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.

Feb 26 '07 #1
1 2546
SAL
If you need to pass in a search pattern for GetFiles, you might want to use
Directory.GetFi les instead of DirectoryInfo.G etFiles.
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.GetUpperB ound(0)

S

"jobs" <jo**@webdos.co mwrote in message
news:11******** *************@t 69g2000cwt.goog legroups.com...
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(f ilename)
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.

Feb 26 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
20199
by: Demetri | last post by:
Using the GetFiles method of the DirectoryInfo instance one can pass in a search pattern of string type. For example: DirectoryInfo di = new DirectoryInfo("C:\temp"); FileInfo fi = di.GetFiles("*.doc"); That code would return all the files with the doc extension in the C:\temp folder. No problem.
4
4681
by: Pluto | last post by:
Hi, I want to get a list of files matching certain extensions, such as "*.jpg;*.gif" (i.e. all files ending with .jpg and .gif). I was using DirectoryInfo.GetFiles(string) method. Unfortunately it appears that I cannot have something like: dirInfo.GetFiles("*.jpg;*.gif"); // where dirInfo is of type DirectoryInfo
0
459
by: Glenn Venzke | last post by:
I have an aspx page that is set up to copy backed-up DB files from a shared directory to a local folder. For some reason, it is being denied access to the network share. I have the web app running under a domain account that I know for a fact has access. it works fine when I log on to the network and browse the directory manually. Even when I...
8
1892
by: Lyners | last post by:
I have code that retrieves all of the file names within a directory. After retriving them, I display the information in a datagrid. What I would like to do is add an extra output column on the directory info that would contain the file name without the extension. Can I add an attribute or an entry to accomplish this? If so, how, if not, is...
3
2373
by: xenophon | last post by:
This following innocuous code: System.IO.DirectoryInfo fff = new System.IO.DirectoryInfo(); System.IO.FileInfo ppp = fff.GetFiles( Request.MapPath(".") ); for( int ccc=0 ; ccc < ppp.Length ; ccc++ ) { System.Web.HttpResponse.Response.Write( "<a href=\"" + Request.MapPath(".") + "/" + HttpUtility.HtmlEncode(ppp.Name) + "\">link</a>" );
5
6484
by: CJ Taylor | last post by:
Hey Everyone, Sorry haven't been around to answer questions as much as usual (or at all for that matter) just been engrossed in a project. Anyways, dealing with an issue using DirectoryInfo.GetFiles wondering if anyone had the same issues I built my function to get the files, using a searchPattern filter (*.tif) in which case I have...
13
2596
by: Tom Scales | last post by:
OK, I admit, I am not a VB.NET expert and am still learning, but have run into an annoying problem. I'm writing a program that has to search the file system and therefore processes large numbers of directories and files. I've figured out DirectoryInfo (it's pretty simple), but when I invoke DirectoryInfo.GetFiles (or even...
2
22953
by: =?Utf-8?B?RGFuaWVsIENvcnLDqmE=?= | last post by:
Hi, I've been trying to use Directory.GetFiles() and also DirectoryInfo.GetFiles() to list files on a remote server using "\\server_name\dir_name" like paths. It works fine on a test windows app, but I get an access error message when the code is running on a asp.net app. First I thought it was just a matter of credentials, so I started...
2
11620
by: RodneyAnonymous | last post by:
Hello everyone. I'm working on a simple utility that lists all files in a given directory with a given extension and outputs the results to a text file. I'm encountering issues while testing where the DirectoryInfo.GetFiles returns nothing. When I put a break in and check it out further, it looks like I'm getting ERROR_ACCESS_DENIED when the...
0
7428
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7941
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7452
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7784
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6014
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
0
5071
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3467
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1916
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
0
738
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.