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 2906 jhardman 3,406
Recognized Expert Specialist
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>
-
%>
jhardman 3,406
Recognized Expert Specialist
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 project 1-solution A
accessing a "save" method in project 2-solution B as well as "getinfo"
method in project 2 accessing a "read" method in project...
|
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. It is
almost like it is trying to implement it's own COM interfaces...
below is the header, and a link to the dll+code:
Zip file with header,...
|
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 thinking...
Can one read in a an xml file that has various embedded nodes (ie: records
that have children records as XML does best) -- possibly not all...
|
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 strInput As String)
return (strInput & " test")
End Sub
| |
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 comes back with all the data intact, except for the
upload object. The text box for "MyFile" (my example) is always cleared.
Why is that and is...
|
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 and not have it
affected by the null? because it is right now causes truncated data at wierd
places... but as soon as i manually with a hex editor...
|
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 selects?
thanks...
|
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 'System.Security.Permissions.FileIOPermission,
mscorlib, Version=2.0.0.0, Culture=neutral,
PublicKeyToken=b77a5c561934e089' failed. (machine.config) --->...
|
by: MikeJ |
last post by:
make a While loop
ofs = TextFileServer("somefile")
string srow
while (ofs=false)
{
srow=ofs.getRow();
Console.Writeline(srow);
}
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it. ...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert...
| |
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |