Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 1.0 and 1.1 > ASP.NET 1.0 and 1.1 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old January 14th, 2008, 04:17 PM
Authorized User
Points: 254, Level: 5
Points: 254, Level: 5 Points: 254, Level: 5 Points: 254, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2007
Location: , , .
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.

  #2 (permalink)  
Old January 14th, 2008, 07:30 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
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?

  #3 (permalink)  
Old January 14th, 2008, 11:11 PM
Wrox Author
Points: 13,255, Level: 49
Points: 13,255, Level: 49 Points: 13,255, Level: 49 Points: 13,255, Level: 49
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Oct 2005
Location: Ohio, USA
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
================================================== =========
  #4 (permalink)  
Old January 15th, 2008, 03:19 PM
Authorized User
Points: 254, Level: 5
Points: 254, Level: 5 Points: 254, Level: 5 Points: 254, Level: 5
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Mar 2007
Location: , , .
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!

  #5 (permalink)  
Old January 15th, 2008, 03:48 PM
Friend of Wrox
Points: 2,101, Level: 18
Points: 2,101, Level: 18 Points: 2,101, Level: 18 Points: 2,101, Level: 18
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2003
Location: , , .
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.

 


Thread Tools
Display Modes

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 Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
MAX/MIN Value Help slbibs SQL Server 2005 4 November 6th, 2007 03:00 AM
MIN( MAX( UPDATE Stuart Stalker SQL Language 3 February 21st, 2007 06: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 05:04 AM



All times are GMT -4. The time now is 07:12 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.