Quote:
quote:Originally posted by crabjoe
I found a sample script in ASP that gives me a directory listing, but it's no help in figuring out how to just grab one filename where the name may change slightly.
Thanks.
|
You have posted in the ASP.NET forum so I will assume that your reference to "ASP" above is a reference to an ASP.NET script.
So with that out of the way, the solution to this is very simple:
System.IO.DirectoryInfo dir = new System.IO.DirectoryInfo();
System.IO.FileInfo[] files = new System.IO.FileInfo();
files = dir.GetFiles("");
GetFiles() has a return type of FileInfo[] which is just an array of files so:
To get access to the first file in the directory you would do:
files[0]
and the last file
files[files.GetUpperBound(0)]
By doing this you are making the assumption that first file returned by GetFiles is the one that you want and vice versa for the last file.
Just be careful, you are working with IO here and if you have large amounts of files that you are loading this can become slow and bog down your server.
hth.
================================================== =========
Read this if you want to know how to get a correct reply for your question:
http://www.catb.org/~esr/faqs/smart-questions.html
================================================== =========
.: Wrox Technical Editor :.
Wrox Books 24 x 7
================================================== =========