473,396 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

ASP File System Object Question

3
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.
Feb 15 '07 #1
4 2901
jhardman
3,406 Expert 2GB
it may be easiest to pull up all of the files with the FSO, then only display the files you want. i.e.:
Expand|Select|Wrap|Line Numbers
  1. if datediff("d", docDate, currentDate) >= 0 then
  2.    'code to display the file
  3. else
  4.    'ignore future files
  5. end if
  6.  
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
Feb 16 '07 #2
vdown
3
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.
Expand|Select|Wrap|Line Numbers
  1. <%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
  2. <!--#include file="shared_functions.asp" -->
  3. <%
  4.     On Error Resume Next
  5.  
  6.     ' Now to the Runtime code:
  7.     Dim strPath   'Path of directory to show
  8.     Dim strCurrentFolderPath
  9.     Dim objFSO                    'FileSystemObject variable
  10.     Dim objArchiveFolder         'Folder variable
  11.     Dim objCurrentFolder        'Folder for the current month
  12.     Dim objItem                   'Variable used to loop through the contents of the folder
  13.     Dim NoFiles                      'The number of files in a folder
  14.     Dim varChain                'Hold the Chain
  15.     Dim SortedFiles                'Sorted files
  16.     Dim DisplayName                '
  17.     Dim TargetMonth 
  18.     Dim TargetYear
  19.     Dim FolderDate
  20.     Dim CorrectedDate2
  21.                 '
  22.     ' Create our FSO
  23.     Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
  24.  
  25.     'FolderDate=Date()
  26.  
  27.     'Done indirectly to prevent hacks
  28.     Function getChain()
  29.  
  30.     (not relavent)
  31.             End Function
  32.  
  33.     Function AutoCorrectDate(FOLDERNAME)
  34.         temp = FOLDERNAME
  35.         'response.Write(temp)
  36.         'take the days from the beginning
  37.         part1 = mid(temp,1,2)
  38.         'Add the / in between to make 101006 to 10/
  39.         part1 =  part1 & "/"
  40.  
  41.         'add a slash between the month and year
  42.         part2 = mid(temp,3,2)
  43.         part2 =  part2 & "/20"
  44.  
  45.         'Finally add a the rest of the year on the end
  46.         part3= mid(temp,5,2)
  47.  
  48.         AutoCorrectDate = part1 & part2 & part3
  49.     'response.write(AutoCorrectDate)
  50.     End Function
  51.     ' NOTE: As currently implemented, this needs to end with the \
  52.  
  53.  
  54.     If Request.QueryString("archive") <> "" then
  55.  
  56.         TargetMonth  = Request.QueryString("archive")
  57.  
  58.         TargetYear   = Request.QueryString("year")
  59.  
  60.         strPath = ".\" & getChain & "\" '& year(now) & "\"
  61.  
  62.             if TargetYear <> "" then
  63.                 'If it's a Year
  64.  
  65.                 strCurrentFolderPath = ".\" & getChain &"\" & TargetYear 
  66.  
  67.             Elseif targetmonth <> "" and TargetYear <> "" then
  68.                 'If it's a month
  69.  
  70.                 strCurrentFolderPath = ".\" & getChain &"\" & targetYear & "\" & TargetMonth & "\"
  71.  
  72.             Else 
  73.  
  74.                 strCurrentFolderPath = ".\" & getChain &"\" & year(now) & "\" & Monthname(month(now)) & "\"
  75.  
  76.             End if
  77.  
  78.     Else
  79.         TargetMonth = MonthName(Month(now))
  80.  
  81.         strPath = ".\" & getChain '& "\" & year(now) & "\"
  82.  
  83.         strCurrentFolderPath = ".\" & getChain &"\" & year(now) & "\" & TargetMonth & "\"
  84.  
  85.     End if
  86.  
  87.  
  88.  
  89.     'Sub HandleError
  90.         'cDate("10/10/06")
  91.         'Response.Write("A runtime Error has occured")
  92.     'End Sub
  93.  
  94.  
  95.  
  96.     'Make sure a folder exists, if it doesn't Use last months
  97.     'if objFSO.FolderExists(strCurrentFolderPath) = False then
  98.         'strCurrentFolderPath = ".\(removed)\" & year(now) & "\" & MonthName(Month(now)-1) & "\"
  99.     'end if    
  100.     ' Get a handle on our folder
  101.     Set objArchiveFolder = objFSO.GetFolder(Server.MapPath(strPath))
  102.     Set objCurrentFolder = objFSO.GetFolder(Server.MapPath(strCurrentFolderPath))
  103.  
  104.     'if objFSO.GetFolder(Server.MapPath(strCurrentFolderPath)) then
  105.     '    newPath = ".\" & getChain &"\" & year(now) & "\" & MonthName(7) & "\"
  106.     '    
  107.     '    set objCurrentFolder = objFSO.GetFolder(Server.MapPath(newPath))
  108.     'end if
  109.  
  110.     set SortedFiles    = server.CreateObject("ADODB.recordset")
  111.  
  112.     With SortedFiles.fields
  113.         .Append "Name", 200, 200
  114.         .Append "DateLastModified", 7
  115.         .Append "DateCreated", 7
  116.         .Append "Size", 3
  117.         .Append "FilesCount", 3
  118.         .Append "FoldersCount", 3
  119.     End With
  120.  
  121.     SortedFiles.open()
  122.     'SortedFiles.filter = "size < 50000"
  123.     For Each objItem in objCurrentFolder.SubFolders
  124.         SortedFiles.addnew
  125.  
  126.         SortedFiles("name") = objItem.name
  127.         SortedFiles("DateLastModified") = objItem.DateLastModified
  128.         SortedFiles("DateCreated") = objItem.DateCreated
  129.         SortedFiles("Size") = objitem.size
  130.         SortedFiles("FilesCount") = objItem.files.count
  131.  
  132.         SortedFiles.update
  133.     next
  134.  
  135.     'response.write(sortedfiles)
  136.     'response.Write(folderdate)
  137.     SortedFiles.Sort = "Name DESC"
  138. %>
  139. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  140. <html xmlns="http://www.w3.org/1999/xhtml">
  141. <head>
  142. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  143. <title>Click: UK &amp; Ireland Press adverts</title>
  144. <link href="press.css" rel="stylesheet" type="text/css" />
  145. </head>
  146.  
  147. <body>
  148. <div id="wrapper">
  149. <!--    <div id="header">
  150.         <h1>Press Ads</h1>
  151.     </div> -->
  152.     <div id="main_content">
  153.         <img src="banner/banner.gif" height="80" width="776" alt="Press Adverts" />
  154.         <!--Menu begin -->
  155.         <!--#include file="menu.html" -->
  156.         <!--Menu end -->
  157.         <!-- Cut and paste this section as needed, multiple "listing"s go in a listings
  158.         Cut and paste date, week divs as required.
  159.         <div class="listings">
  160.             <div class="listing">
  161.                 <div class="bullet"></div>
  162.                 <div class="paper">The Sun</div>
  163.                 <div class="categories">Sony Camcorders</div>
  164.                 <div class="link">Save Millions </div>
  165.             </div>
  166.         </div> -->
  167. <!--Don not replace/paste/edit any content above this line-->
  168.         <!--Week and year begin -->
  169.         <!--<h2>Wk 49 <span class="little">2005/2006</span></h2> -->
  170.         <!--Week and year end -->
  171.         <!--Date begin -->
  172.         <div class="date">
  173.             <b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>
  174.             <%= TargetMonth & " " & Year(now)%><!--Above & below b elements provide the rounded corners-->
  175.             <b class="rtop"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>        
  176.         </div>
  177.         <!--Date end -->
  178.         <!--Listings begin -->
  179.         <div class="listings">
  180.             <table class="listing">
  181.                 <tr>
  182.                     <th>File Name:</th>
  183.                     <th>Number of Ads</th>
  184.                     <th>Date Added:</th>
  185.                     <th>Total Size of PDF's</th>
  186.               </tr>
  187.                 <%
  188.  
  189.  
  190.                 ' Now that I've done the SubFolders, do the files!
  191.  
  192.                 Do While not SortedFiles.EOF 
  193.                 'and correcteddate2 >= folderdate
  194.                 'response.write(SortedFiles.Fields("name").value)
  195.                 'and AutoCorrectDate <= FolderDate
  196.  
  197.                 'Check for non numeric file names
  198.                 If isnumeric(SortedFiles.Fields("name").value) then
  199.                 correctedDate = AutoCorrectDate(SortedFiles.Fields("name").value)
  200.  
  201.                 %>
  202.                 <tr>
  203.                     <td class="paper">
  204.                         <img src="images/folder.gif" alt="folder icon" />
  205.                         <%= "<a href=" & chr(34) & "Fresh_press.asp?date=" & SortedFiles.Fields("name").value & "&chain=" & varChain & chr(34)& ">"  & FormatDateTime(correctedDate,1) & "</a>"%>
  206.                     </td>
  207.                       <td><%= SortedFiles.Fields("FilesCount").value %></td>
  208.                     <td><%= FormatDateTime(SortedFiles.Fields("DateCreated").value,2) %></td>
  209.                     <td><%=  BtyeConversion(SortedFiles.Fields("size").value) %></td>
  210.               </tr>
  211.                 <%
  212.                 End if
  213.                 SortedFiles.MoveNext
  214.                 Loop 'objCurrentFolder 
  215.             %>
  216.           </table>
  217.         </div>
  218.  
  219.         <!----------------------------------------- Archive Starts here ---------------------------------------------->
  220.         <hr />
  221.         <div class="date">
  222.             <b class="rtop"><b class="r1"></b><b class="r2"></b><b class="r3"></b><b class="r4"></b></b>
  223.             Press Ads Archive
  224.             <b class="rtop"><b class="r4"></b><b class="r3"></b><b class="r2"></b><b class="r1"></b></b>        
  225.         </div>
  226.         <div class="listings">
  227.             <table class="listing">
  228.                 <tr>
  229.                     <th>File Name:</th>
  230.                     <th>Number of Days:</th>
  231.                     <th>Date Created:</th>
  232.                     <th>File Type:</th>
  233.               </tr>
  234.                 <%
  235.                     ' Now that I've done the SubFolders, do the files!
  236.                     For Each objItem In objArchiveFolder.SubFolders
  237.  
  238.                     'Test to see if it's a year
  239.                         If isNumeric(objItem.Name) then                    
  240.                 %>
  241.                 <tr>
  242.                     <td class="paper"><img src="images/folder.gif" alt="folder" /><%= "<a href=" & chr(34) & "Fresh_press_archive.asp?chain=" & varchain & "&amp;" &  "year=" & objItem.Name & "&amp;" & chr(34) & ">" & objItem.Name %></a></td>
  243.                       <td><%= objItem.SubFolders.count %></td>
  244.                     <td><%= FormatDateTime(objItem.DateCreated,2) %></td>
  245.                     <td><%= objItem.Type %></td>
  246.               </tr>
  247.                 <%
  248.                         End if
  249.  
  250.                     Next 'objItem
  251.  
  252.                     ' All done!  Kill off our object variables.
  253.                     Set objItem = Nothing
  254.                     Set objArchiveFolder = Nothing
  255.                     Set objFSO = Nothing
  256.                 %>
  257.           </table>
  258.         </div>
  259.     </div>
  260. </div>
  261. </body>
  262. </html>
  263. %>
Feb 19 '07 #3
jhardman
3,406 Expert 2GB
Ok, I would insert 2 lines. First:
Expand|Select|Wrap|Line Numbers
  1.     'Check for non numeric file names
  2.     If isnumeric(SortedFiles.Fields("name").value) then
  3.     correctedDate = AutoCorrectDate(SortedFiles.Fields("name").value)
  4.         'next line is the one I insert
  5.         if dateDiff("d", correctedDate, now) < 0 then
  6.  
and then add an extra end if:
Expand|Select|Wrap|Line Numbers
  1.                 <%
  2.     End if         'this is the line I added
  3.     End if
  4.     SortedFiles.MoveNext
  5.     Loop 'objCurrentFolder 
  6.  
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"
Feb 21 '07 #4
vdown
3
Thats it, thanks very much.

You were right switched the less than to the greater than and it worked.
Feb 21 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

7
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...
14
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
0
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....
5
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...
10
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...
6
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...
12
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...
3
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...
3
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...
4
by: MikeJ | last post by:
make a While loop ofs = TextFileServer("somefile") string srow while (ofs=false) { srow=ofs.getRow(); Console.Writeline(srow); }
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
marktang
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,...
0
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...
0
agi2029
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,...
0
isladogs
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.