Im no ASP expert but have inherited a site that scans a load of folders for PDFs using the file system object.
All the PDFs are held in a time based heriarchical folder structure i.e. Year\Month\Date (in format 150207, thats UK date).
The first page lists the current month with all the days that have folders. In the format (15 February 2007) a function converts the folder name to this format. All the folders are then put in an array and sorted in date order,
I want to be able to exclude any days in the future. That is its the 15th of Feb today so if there was a folder for the 16th I dont want it to appear until the 16th.
This would be easy with a SQL statement but I cant find any relavent reference to do it with a File System Array. As the only way of identifying the date of the PDFs is from their parent folder name.
4 2901
it may be easiest to pull up all of the files with the FSO, then only display the files you want. i.e.: -
if datediff("d", docDate, currentDate) >= 0 then
-
'code to display the file
-
else
-
'ignore future files
-
end if
-
I can never remember date function syntax, but it is pretty close to that.
The "else" clause can obviously be left out.
If you post your FSO code I might be able to give other suggestions , maybe filter it out as you load
Here the code of the first page, It automatically goes into a specific folder based on the query string in the address bar.
There is nothing too relavent in the include file either.
Thx for any help. -
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
-
<!--#include file="shared_functions.asp" -->
-
<%
-
On Error Resume Next
-
-
' Now to the Runtime code:
-
Dim strPath 'Path of directory to show
-
Dim strCurrentFolderPath
-
Dim objFSO 'FileSystemObject variable
-
Dim objArchiveFolder 'Folder variable
-
Dim objCurrentFolder 'Folder for the current month
-
Dim objItem 'Variable used to loop through the contents of the folder
-
Dim NoFiles 'The number of files in a folder
-
Dim varChain 'Hold the Chain
-
Dim SortedFiles 'Sorted files
-
Dim DisplayName '
-
Dim TargetMonth
-
Dim TargetYear
-
Dim FolderDate
-
Dim CorrectedDate2
-
'
-
' Create our FSO
-
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
-
-
'FolderDate=Date()
-
-
'Done indirectly to prevent hacks
-
Function getChain()
-
-
(not relavent)
-
End Function
-
-
Function AutoCorrectDate(FOLDERNAME)
-
temp = FOLDERNAME
-
'response.Write(temp)
-
'take the days from the beginning
-
part1 = mid(temp,1,2)
-
'Add the / in between to make 101006 to 10/
-
part1 = part1 & "/"
-
-
'add a slash between the month and year
-
part2 = mid(temp,3,2)
-
part2 = part2 & "/20"
-
-
'Finally add a the rest of the year on the end
-
part3= mid(temp,5,2)
-
-
AutoCorrectDate = part1 & part2 & part3
-
'response.write(AutoCorrectDate)
-
End Function
-
' NOTE: As currently implemented, this needs to end with the \
-
-
-
If Request.QueryString("archive") <> "" then
-
-
TargetMonth = Request.QueryString("archive")
-
-
TargetYear = Request.QueryString("year")
-
-
strPath = ".\" & getChain & "\" '& year(now) & "\"
-
-
if TargetYear <> "" then
-
'If it's a Year
-
-
strCurrentFolderPath = ".\" & getChain &"\" & TargetYear
-
-
Elseif targetmonth <> "" and TargetYear <> "" then
-
'If it's a month
-
-
strCurrentFolderPath = ".\" & getChain &"\" & targetYear & "\" & TargetMonth & "\"
-
-
Else
-
-
strCurrentFolderPath = ".\" & getChain &"\" & year(now) & "\" & Monthname(month(now)) & "\"
-
-
End if
-
-
Else
-
TargetMonth = MonthName(Month(now))
-
-
strPath = ".\" & getChain '& "\" & year(now) & "\"
-
-
strCurrentFolderPath = ".\" & getChain &"\" & year(now) & "\" & TargetMonth & "\"
-
-
End if
-
-
-
-
'Sub HandleError
-
'cDate("10/10/06")
-
'Response.Write("A runtime Error has occured")
-
'End Sub
-
-
-
-
'Make sure a folder exists, if it doesn't Use last months
-
'if objFSO.FolderExists(strCurrentFolderPath) = False then
-
'strCurrentFolderPath = ".\(removed)\" & year(now) & "\" & MonthName(Month(now)-1) & "\"
-
'end if
-
' Get a handle on our folder
-
Set objArchiveFolder = objFSO.GetFolder(Server.MapPath(strPath))
-
Set objCurrentFolder = objFSO.GetFolder(Server.MapPath(strCurrentFolderPath))
-
-
'if objFSO.GetFolder(Server.MapPath(strCurrentFolderPath)) then
-
' newPath = ".\" & getChain &"\" & year(now) & "\" & MonthName(7) & "\"
-
'
-
' set objCurrentFolder = objFSO.GetFolder(Server.MapPath(newPath))
-
'end if
-
-
set SortedFiles = server.CreateObject("ADODB.recordset")
-
-
With SortedFiles.fields
-
.Append "Name", 200, 200
-
.Append "DateLastModified", 7
-
.Append "DateCreated", 7
-
.Append "Size", 3
-
.Append "FilesCount", 3
-
.Append "FoldersCount", 3
-
End With
-
-
SortedFiles.open()
-
'SortedFiles.filter = "size < 50000"
-
For Each objItem in objCurrentFolder.SubFolders
-
SortedFiles.addnew
-
-
SortedFiles("name") = objItem.name
-
SortedFiles("DateLastModified") = objItem.DateLastModified
-
SortedFiles("DateCreated") = objItem.DateCreated
-
SortedFiles("Size") = objitem.size
-
SortedFiles("FilesCount") = objItem.files.count
-
-
SortedFiles.update
-
next
-
-
'response.write(sortedfiles)
-
'response.Write(folderdate)
-
SortedFiles.Sort = "Name DESC"
-
%>
-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
-
<html xmlns="http://www.w3.org/1999/xhtml">
-
<head>
-
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
-
<title>Click: UK & Ireland Press adverts</title>
-
<link href="press.css" rel="stylesheet" type="text/css" />
-
</head>
-
-
<body>
-
<div id="wrapper">
-
<!-- <div id="header">
-
<h1>Press Ads</h1>
-
</div> -->
-
<div id="main_content">
-
<img src="banner/banner.gif" height="80" width="776" alt="Press Adverts" />
-
<!--Menu begin -->
-
<!--#include file="menu.html" -->
-
<!--Menu end -->
-
<!-- Cut and paste this section as needed, multiple "listing"s go in a listings
-
Cut and paste date, week divs as required.
-
<div class="listings">
-
<div class="listing">
-
<div class="bullet"></div>
-
<div class="paper">The Sun</div>
-
<div class="categories">Sony Camcorders</div>
-
<div class="link">Save Millions </div>
-
</div>
-
</div> -->
-
<!--Don not replace/paste/edit any content above this line-->
-
<!--Week and year begin -->
-
<!--<h2>Wk 49 <span class="little">2005/2006</span></h2> -->
-
<!--Week and year end -->
-
<!--Date begin -->
-
<div class="date">
-
<b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>
-
<%= TargetMonth & " " & Year(now)%><!--Above & below b elements provide the rounded corners-->
-
<b class="rtop"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>
-
</div>
-
<!--Date end -->
-
<!--Listings begin -->
-
<div class="listings">
-
<table class="listing">
-
<tr>
-
<th>File Name:</th>
-
<th>Number of Ads</th>
-
<th>Date Added:</th>
-
<th>Total Size of PDF's</th>
-
</tr>
-
<%
-
-
-
' Now that I've done the SubFolders, do the files!
-
-
Do While not SortedFiles.EOF
-
'and correcteddate2 >= folderdate
-
'response.write(SortedFiles.Fields("name").value)
-
'and AutoCorrectDate <= FolderDate
-
-
'Check for non numeric file names
-
If isnumeric(SortedFiles.Fields("name").value) then
-
correctedDate = AutoCorrectDate(SortedFiles.Fields("name").value)
-
-
%>
-
<tr>
-
<td class="paper">
-
<img src="images/folder.gif" alt="folder icon" />
-
<%= "<a href=" & chr(34) & "Fresh_press.asp?date=" & SortedFiles.Fields("name").value & "&chain=" & varChain & chr(34)& ">" & FormatDateTime(correctedDate,1) & "</a>"%>
-
</td>
-
<td><%= SortedFiles.Fields("FilesCount").value %></td>
-
<td><%= FormatDateTime(SortedFiles.Fields("DateCreated").value,2) %></td>
-
<td><%= BtyeConversion(SortedFiles.Fields("size").value) %></td>
-
</tr>
-
<%
-
End if
-
SortedFiles.MoveNext
-
Loop 'objCurrentFolder
-
%>
-
</table>
-
</div>
-
-
<!----------------------------------------- Archive Starts here ---------------------------------------------->
-
<hr />
-
<div class="date">
-
<b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>
-
Press Ads Archive
-
<b class="rtop"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>
-
</div>
-
<div class="listings">
-
<table class="listing">
-
<tr>
-
<th>File Name:</th>
-
<th>Number of Days:</th>
-
<th>Date Created:</th>
-
<th>File Type:</th>
-
</tr>
-
<%
-
' Now that I've done the SubFolders, do the files!
-
For Each objItem In objArchiveFolder.SubFolders
-
-
'Test to see if it's a year
-
If isNumeric(objItem.Name) then
-
%>
-
<tr>
-
<td class="paper"><img src="images/folder.gif" alt="folder" /><%= "<a href=" & chr(34) & "Fresh_press_archive.asp?chain=" & varchain & "&" & "year=" & objItem.Name & "&" & chr(34) & ">" & objItem.Name %></a></td>
-
<td><%= objItem.SubFolders.count %></td>
-
<td><%= FormatDateTime(objItem.DateCreated,2) %></td>
-
<td><%= objItem.Type %></td>
-
</tr>
-
<%
-
End if
-
-
Next 'objItem
-
-
' All done! Kill off our object variables.
-
Set objItem = Nothing
-
Set objArchiveFolder = Nothing
-
Set objFSO = Nothing
-
%>
-
</table>
-
</div>
-
</div>
-
</div>
-
</body>
-
</html>
-
%>
Ok, I would insert 2 lines. First: -
'Check for non numeric file names
-
If isnumeric(SortedFiles.Fields("name").value) then
-
correctedDate = AutoCorrectDate(SortedFiles.Fields("name").value)
-
'next line is the one I insert
-
if dateDiff("d", correctedDate, now) < 0 then
-
and then add an extra end if: -
<%
-
End if 'this is the line I added
-
End if
-
SortedFiles.MoveNext
-
Loop 'objCurrentFolder
-
the dateDiff function is the one that checks, and it just subtracts one date from the other. The ony problem is, I never remember which way it works, so if this does the opposite of what you want, you know you need to switch it to " > 0"
Thats it, thanks very much.
You were right switched the less than to the greater than and it worked.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Brian Sabolik |
last post by:
I'm not sure if I've broken any Object Oriented rules or not, but ...
I have projects in 2 different solutions that need to use each other's
methods. Therefore I may have an "update" method in...
|
by: vince |
last post by:
Can I add (append) to an xml file that already contains a
serialized object, and be able to deserialize to either
or both objects from the same file...??? How is this
done...??
thanks,
vince
|
by: Lokkju |
last post by:
I am pretty much lost here - I am trying to create a managed c++
wrapper for this dll, so that I can use it from c#/vb.net, however, it
does not conform to any standard style of coding I have seen....
|
by: Sky |
last post by:
What makes something a valid DataSource? What methods/iterators/etc?
Why do I ask?
I do understand that a DataSet is based on an XML structure...but it's too
table structured for what I am...
|
by: bienwell |
last post by:
Hi,
I have a question about file included in ASP.NET. I have a file that
includes all the Sub functions (e.g FileFunct.vb). One of the functions
in this file is :
Sub TestFunct(ByVal...
|
by: tshad |
last post by:
I have an upload file input as:
<input id="MyFile" style="width:300px" type="File" runat="Server">
This works fine, but I find that if my page doesn't pass validation during
postback, the page...
|
by: Brian Henry |
last post by:
first question... I have a flat file which unfortinuatly has columns
seperated by nulls instead of spaces (a higher up company created it this
way for us) is there anyway to do a readline with this...
|
by: forest demon |
last post by:
for example, let's say I do something like,
System.Diagnostics.Process.Start("notepad.exe","sample.txt");
if the user does a SaveAs (in notepad), how can i capture the path that
the user...
|
by: Mike |
last post by:
Hi
I have problem as folow:
Caught Exception: System.Configuration.ConfigurationErrorsException:
An error occurred loading a configuration file: Request for the
permission of type...
|
by: MikeJ |
last post by:
make a While loop
ofs = TextFileServer("somefile")
string srow
while (ofs=false)
{
srow=ofs.getRow();
Console.Writeline(srow);
}
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
|
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,...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |