ASP file dates

Downloads: www.mtm2.com/~mtmg/utilities.html
Post Reply
User avatar
Phineus
Glow Ball
Posts: 24
Joined: Tue Feb 02, 1999 7:00 pm

ASP file dates

Post by Phineus »

The goal is to list files according to date. In perl, it would look something like this:

Code: Select all

$dir = '/home/blah/blah';

opendir (DIR, $dir) || die "Can't opendir $dir: $!";
 @ondisk = sort readdir (DIR);
closedir (DIR);

foreach $file (@ondisk) {
  $date = (stat "$dir/$file")[10];
  if ($date [is after 01/10/03]) {
    print "$file";
  }
}
Can that be done using ASP and how might you go about it? Thanks.
User avatar
Phineus
Glow Ball
Posts: 24
Joined: Tue Feb 02, 1999 7:00 pm

Post by Phineus »

Code: Select all

<%

'Declare our FileSystemObject variable 
Dim objFSO 
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")

'Declare our folder variable 
Dim objFolder 

'Now, what is our web's root folder? 
Dim strRootFolder 
strRootFolder = "C:\Path\Blah\Blah" 

'set our folder object to the web root folder 
Set objFolder = objFSO.GetFolder(strRootFolder)

 'Declare a file object and a couple variables
Dim objFile 
Dim Mydate, ArbDate
Dim iDiff, MyCount
ArbDate = DateSerial(1970, 1, 1)
MyCount = 0

'Now, use a for each...next to loop through the Files collection 

For Each objFile in objFolder.Files 
  Mydate = FormatDateTime(objFile.DateLastModified, vbShortDate)
  iDiff = DateDiff("m", ArbDate, objFile.DateLastModified)
  if iDiff < 24 And iDiff > -1 then
   Response.Write objFile.Name & " ( " & Mydate & " ) " &iDiff& " <BR>" 
   MyCount = MyCount + 1
  end if
Next

   Response.Write MyCount

%>


Sources:

Iterating through the FileSystemObject Collections
http://www.4guysfromrolla.com/webtech/f ... faq5.shtml

Using the FileSystemObject for Web Site Maintenance
http://www.4guysfromrolla.com/webtech/091499-1.shtml

FileSystemObject
http://www.4guysfromrolla.com/aspfaqs/S ... ?FAQID=118

Dates and Times
http://www.4guysfromrolla.com/aspfaqs/S ... p?FAQID=18
http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=183

Strings
http://www.4guysfromrolla.com/aspfaqs/S ... p?FAQID=17


I like talking to myself :roll:
User avatar
ch_2005
Member
Posts: 696
Joined: Thu Apr 19, 2001 2:01 pm
Location: USA and Proud of it.
Contact:

Post by ch_2005 »

lol - i looked at the answer - then i was like - wait who was that - then i was like who asked the question then? - oh lol - then i was like i should comment that he's talking to himself, then i'm like - oh - when i saw the bottom of your post.
Keep on MTMing,
CH_2005
<a href="http://ch.mtm2.com/">Visit my site</a>
Post Reply