473,569 Members | 2,480 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

ASP File System Object Question

3 New Member
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 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.:
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 New Member
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 Recognized Expert Specialist
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 New Member
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
2750
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...
14
14284
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
3921
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,...
5
1757
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...
10
24052
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
6
4127
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...
12
2958
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...
3
3991
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...
3
12038
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) --->...
4
2115
by: MikeJ | last post by:
make a While loop ofs = TextFileServer("somefile") string srow while (ofs=false) { srow=ofs.getRow(); Console.Writeline(srow); }
0
7615
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...
0
7924
Oralloy
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. ...
1
7677
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...
0
7979
tracyyun
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...
0
6284
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5219
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...
0
3653
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...
1
2115
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

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.