Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 14th, 2008, 05:17 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default How does one get the Max or Min Filename?

Ok, here's what I'm trying to do. I'm trying to get the max or min of a filename in a given directory.

Let's say I have 3 files that have year/month in the name as this.

A_200801.txt
A_200802.txt
A_200803.txt

They are all in the same directory and I want my ASP to give me back the max filename of A_200803.txt. If it were sql, I would just go a select max(filename) from table where filename like 'A_%', but being it's not SQL I can't.

So how is this done?? 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.

 
Old January 14th, 2008, 08:30 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

Why can't you put the filenames into a temp table [#whatevertemptable] and select the MAX or MIN from there?

 
Old January 15th, 2008, 12:11 AM
Wrox Author
 
Join Date: Oct 2005
Posts: 4,104
Thanks: 1
Thanked 64 Times in 64 Posts
Send a message via AIM to dparsons
Default

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
================================================== =========
 
Old January 15th, 2008, 04:19 PM
Authorized User
 
Join Date: Mar 2007
Posts: 54
Thanks: 0
Thanked 0 Times in 0 Posts
Default

dparsons,

Sorry about the post. I was looking for classic ASP. I didn't realize I posted in the wrong forum till your post. Regardless, I'm planning on learning .Net within the next few months so your reply still helps. I'm going to now repost in the classic ASP forum.

Thanks!

 
Old January 15th, 2008, 04:48 PM
Friend of Wrox
 
Join Date: Jul 2003
Posts: 599
Thanks: 6
Thanked 3 Times in 3 Posts
Default

If you're putting the files up with an uploader you could always write the filename and path to the database and you'd be in like Flint.






Similar Threads
Thread Thread Starter Forum Replies Last Post
MAX/MIN Value Help slbibs SQL Server 2005 4 November 6th, 2007 04:00 AM
MIN( MAX( UPDATE Stuart Stalker SQL Language 3 February 21st, 2007 07:10 AM
Min / Max followup danbush XSLT 2 August 31st, 2005 12:02 PM
MAX and MIN ON TD cleytonjordan XSLT 7 July 27th, 2005 12:39 PM
How to use Min,Max,Abs functions braindog_43 XSLT 0 February 7th, 2005 06:04 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.