I have a vbscript that retrieves pdf files and outputs them in a table
with a link to the file plus the date modified. I'm trying with no
luck to sort the links starting with newest file. The file path is
newbusiness/2007. There is a folder for each year. A the top of the
table is a list of links to each year folder. Below is the code:

<%@ Language = "vbScript"%>
<%option Explicit%>
<META NAME="GENERATOR" Content="Microsoft Visual Studio 6.0">
<%
'
****************************************************************************************************
' FSO - Datasource - path to the icon Folder

'
****************************************************************************************************
Dim ObjFSO
Set ObjFSO = CreateObject("Scripting.FileSystemObject") '** Create
FSO

Function getCurrentYear()
getCurrentYear = DatePart("yyyy", Date)
if not ObjFSO.FolderExists(Server.MapPath("newbusiness\" &
getCurrentYear)) then
getCurrentYear = getCurrentYear - 1
end if
Exit Function
End Function


Dim FolderRequest : FolderRequest = Request.QueryString("archive") &
"\" '** grabs the query string passed by the argument "?folder="


If FolderRequest = "\" or Len(Request.QueryString) = 0 then
If ObjFSO.FolderExists(Server.MapPath("newbusiness\" &
getCurrentYear)) then
FolderRequest = getCurrentYear & "\"
else
getCurrentYear = getCurrentYear - 1
FolderRequest = getCurrentYear & "\"
end if
end if

Dim FolderPath
FolderPath="newbusiness\" & FolderRequest '** newbusiness folder
path/

Dim RootFolder, NavPath, s, n
Dim f1
Dim sf

MapMyDrive()

'==============================================================
' Sets up the folder path where the pdf files will be read from
'==============================================================
Private Sub MapMyDrive()
On Error Resume Next

Set RootFolder = ObjFSO.GetFolder(Server.MapPath(FolderPath))

If Err.Number <> 0 then
FolderPath = "newbusiness\" & getCurrentYear & "\" '** newbusiness
folder path/
Err.Clear()
else
FolderPath= "newbusiness\" & FolderRequest
end if


Set RootFolder = ObjFSO.GetFolder(Server.MapPath("newbusiness/"))
'** Root folder = New Business folder
Set NavPath = ObjFSO.GetFolder(Server.MapPath(FolderPath)) '**
set what files are shownview depending on what's defined in NavPath

Set sf = RootFolder.SubFolders '** set subfolders to read information
from the /newbusiness folder (top level directory)

Exit Sub
End Sub

Function ShowFolderList(folderspec) '** grabs all the files within a
specific folder and outputs them, with links, as a single string
Dim n
n = 0
For Each f1 in sf
n = n + 1
if n = 1 then
'=== Do Nothing ===
else
s = s & "<font color='#ffffff'>|</font> "
end if
s = s & "<nobr><a href='newbusiness.asp?archive=" & f1.name & "'>" &
UCase(replace(f1.name ,"_"," ")) & "</a></nobr> "
Next
ShowFolderList = s
End Function

'
****************************************************************************************************
' Outer table
'
****************************************************************************************************
%>
<!doctype html public "-//w3c//dtd html 4.0 transitional//en" >
<html>
<head>
<TITLE>New Business Archive for
<%response.Write(replace(replace(FolderRequest, "\", "") ,"_"," "))
%>
</TITLE>
<link rel="stylesheet" href="/CityOfRichmondVirginia.css">
<link rel="stylesheet" href="newbusinessarchive.css" title="New
Business Archive Style Sheet">
</head>
<body bgcolor="#E2DED4" text="#000000" link="#000000" vlink="#000000"
alink="#000000" leftmargin="0" topmargin="0" rightmargin="0"
bottommargin="0" marginwidth="0" marginheight="0" name="top">
<form name="frmMain" method="post" action="index.aspx" id="frmMain">
<input type="hidden" name="__VIEWSTATE" value="dDwxMzE4OTY3MjM2Ozs
+cEc8jXCd4QzwkdirzxyX1EgPR0c=" ID="Hidden1"/>
<div align="center">
<table bgcolor="#333333" width="760" cellspacing="0"
cellpadding="1" border="0" style="background:#333333;width:760px;"
ID="Table1">
<!-- Begin table creating 1px border -->
<tr>
<td>
<table background="" bgcolor="#E2DED4" width="100%"
cellspacing="0" cellpadding="0" border="0" ID="Table3">
<tr>
<td align="center"><script src="/macromediaflashdetect.js"
type="text/javascript"></script>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000"
codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/
swflash.cab#version=6,0,0,0" width="758" height="98"
id="Richmond.Main.Menu" align="middle" >

<param name="movie" value="/PageTemplates/flash/
Richmond.Main.Menu.Smaller.swf?
__ServerName=wwwdev&__PageTemplateName=Default&__PageTemplateType=SmallDeptHeader" /
>
<param name="menu" value="false" />
<param name="allowScriptAccess" value="sameDomain" />
<param name="quality" value="high" />
<param name="scale" value="noscale" />
<param name="wmode" value="transparent" />
<param name="loop" value="false" />
<param name="bgcolor" value="#E2DED4" />
<embed src="/PageTemplates/flash/
Richmond.Main.Menu.Smaller.swf?
__ServerName=wwwdev&__PageTemplateName=Default&__PageTemplateType=SmallDeptHeader"
loop="false" menu="false" quality="high" scale="noscale"
wmode="transparent" bgcolor="#E2DED4" width="758" height="98"
name="Richmond.Main.Menu" align="middle"
allowScriptAccess="sameDomain" type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer" />

</object>
</td>
</tr>

<tr height="15" bgcolor="FEF8E8">
<td></td>
</tr>

<tr>
<td align="center" bgcolor="FEF8E8">

<!-- BEGIN "YOUR DEPARTMENT" CONTENT -->
<table bgcolor="#333333" width="760" border="0" cellpadding="1"
cellspacing="0" align="center"
ID="Table4">
<tr>
<td valign="top" bgcolor="#99cccc">
<table width="100%" border="0" cellspacing="0" cellpadding="1"
ID="Table5">
<tr bgcolor="">
<td colspan="2" align="center">
<span class="pagetitleteal">New Business Archive</
span><br><br>
</td>
</tr>
<tr bgcolor="#999999">
<td colspan="2" align="center">
<%Response.Write "<B>"&ShowFolderList(sf)&"</B>" %>
</td>
</tr>
<tr>
<td colspan="2">
<table width="100%" cellpadding="3" cellspacing="0"
border="1">
<%

'
***************************************************************************************************
' Display pdf files and tables in specific folder
'
***************************************************************************************************
Dim files, fileCountIndex

Set files = NavPath.Files
fileCountIndex = files.count

'
****************************************************************************************************
' Display Number of picture
'
****************************************************************************************************
'Determine how many files are in the directory, and create the
table entries accordingly.
if fileCountIndex = 0 then
Response.Write "<tr><td colspan='2' valign='bottom'>There are <b>"
& fileCountIndex & "</b> records available.<BR>Please choose a
directory above to browse.<br>" _
& "The current list of new business licenses is: " &
setCurrentLicense() & "</td></tr>"
else
if fileCountIndex = 1 then
Response.Write "<tr><td colspan='2' valign='bottom'>There is
<b>" & fileCountIndex & "</b> record available.<br>"_
& "The current list of new business licenses is: " &
setCurrentLicense() & "</td></tr><tr><td align='center'><b>Week
Ending</b></td><td align='center'><b>Posted Date</b></td></tr>"

else
if fileCountIndex >= 2 then
Response.Write "<tr><td colspan='2' valign='bottom'>There are
<b>" & fileCountIndex & "</b> records available.<br>" _
& "The current list of new business licenses is: " &
setCurrentLicense() & "</td></tr><tr><td align='center'><b>Week
Ending</b></td><td align='center'><b>Posted Date</b></td></tr>"
end if
end if
end if
'Code goes here to set the menu navigation


'
=============================================================================
'
===
===
' === Daniel
Dority ===
'
=============================================================================

getHerDone()

'
=============================================================================
' === Outputs the directory of PDFs onto the
page ===
'
=============================================================================
Private Sub getHerDone()
Dim i : i = 0
Dim Name, file, myExt, Link

For Each file in Files
Name = File.Name
Link = Name

myExt = LCase(ObjFSO.GetExtensionName(Name))

Select Case(myExt)
Case "pdf":
Response.Write("<tr>")
Response.Write(" <td valign='middle' width='420'>")
Response.Write(addLinkage(FolderPath, Link,
formatString(Name)))
Response.Write(" </td>")
Response.Write(" <td width='220'>" & (File.DateLastModified) &
"</td>")
Response.Write("</tr>")
Case Else: '=== Do Nothing ===
End Select
Next
Exit Sub
End Sub

'
=============================================================================
' === Gets the latest file in the latest
folder ===
'
=============================================================================
Private Function setCurrentLicense()
Dim currentFolderPath, file, currentFiles, currentFileCountIndex,
currentNavPath
currentFolderPath = "newbusiness\" & getCurrentYear & "\"

Set currentNavPath =
ObjFSO.GetFolder(Server.MapPath(currentFolderPath)) '** set what files
are shownview depending on what's defined in NavPath
Set currentFiles = currentNavPath.Files
currentFileCountIndex = currentFiles.count
Dim i : i = 1

For Each file in currentfiles
Select Case (i = currentFileCountIndex)
Case True: setCurrentLicense = addLinkage(currentFolderPath,
file.Name, formatString(file.Name))
Case Else: '=== Do Nothing ===
End Select
i = i + 1
Next

Set currentNavpath = Nothing
Set currentFiles = Nothing

Exit Function
End Function

'
=============================================================================
' === Formats the filename from "newbusinessMMDDYYYY" to "MM/DD/
YYYY." ===
' ===
ARGUMENTS:
===
' === strLicense -
file.Name ===
'
=============================================================================
Private Function formatString(strLicense)
formatString = Left(Right(replace(strLicense ,"_"," "), 12), 2) _
& "/" & Left(Right(replace(strLicense ,"_"," "), 10), 2) _
& "/" & Left(Right(replace(strLicense ,"_"," "), 8), 4)
Exit Function
End Function

'
=============================================================================
' === Sets the Link Name and File Name into a
Link ===
' ===
ARGUMENTS:
===
' === strFolderPath -
FolderPath ===
' === strLink -
Link ===
' === strName -
Name ===
' === One might use this like
so: ===
' === addLinkage(FolderPath, Link,
Name) ===
'
=============================================================================
Private Function addLinkage(strFolderPath, strLink, strName)
addLinkage = "<a href='" & replace(strFolderPath, "\", "/") &
strLink & "' target='_blank'><span class='fontB'>" & strName & "</
span></a>"
Exit Function
End Function

%>
</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#999999">
<td>
<table width="100%" ID="Table2">
<tr>
<td valign="middle" align="right"><!-- #include
file="adobereader_textwhite.txt" --></td>
</tr>
</table>
</td>
</tr>
</table>
<%
Set Navpath = Nothing
Set RootFolder = Nothing
Set ObjFSO = Nothing
Set sf = Nothing
Set files = Nothing
%>
<!-- END YOUR CONTENT ABOVE -->


</td>
</tr>
</table>

</td>
</tr>
</table>
<!-- END "YOUR DEPARTMENT" CONTENT -->

</td>
</tr>
<tr height="15" bgcolor="FEF8E8">
<td></td>
</tr>

<tr>
<td align="center">
<!-- BEGIN DEFAULT FOOTER FOR THE CITY WEBSITE -->
<table width="100%" border="0" align="center" cellpadding="2"
cellspacing="0" bgcolor="#000000" id="corFooter">
<tr valign="top">
<td>
<table cellspacing="0" cellpadding="0" border="0" width="100%"
id="LNDL">
<tr>
<td><font class="font11pxVerdanaFFFFFF" color="#FFFFFF" title="900
East Broad Street, Richmond, Virginia 23219">&nbsp;&nbsp;900 East
Broad Street, Richmond, Virginia 23219 (804)646-7000 <a href="/
contact.aspx" class="footer" title="City of Richmond Contact
Information Page.">Contact Us.</a> </font></td>

<td align="right" width="110" rowspan="2"><a href="/"><img src="/
images/footer.image.onecityourcity.jpg" width="110" border="0"
alt="The City of Richmond Virginia." title="The City of Richmond
Virginia."></a></td>
</tr>

<tr>
<td><font class="font11pxVerdanaFFFFFF" color="#FFFFFF"
title="Copyright 2000 to 2005, City of Richmond,
Virginia.">&nbsp;&nbsp;&#169;2000-2006 City of Richmond, Virginia. All
rights reserved. <a href="/disclaimer.aspx" class="footer" title="The
Privacy Statement, Disclaimer and Terms of Use for this
site.">Privacy, Disclaimer &amp; Terms.</a> </font></td>
</tr>
</table>

</td>
</tr>
</table>
<!-- END DEFAULT FOOTER FOR THE CITY WEBSITE, LNDL --></td>
</tr>
</table>
</td>
</tr>
<!-- End table creating 1px border -->
</table>

</div>
</form>
</body>
</html>

Re: Sorting in VBscript by McKirahan

McKirahan
Fri Nov 30 16:41:34 PST 2007

<robert.s@att.net> wrote in message
news:f9d974dd-c15a-4b37-9d2d-934036c3ba25@w34g2000hsg.googlegroups.com...
> I have a vbscript that retrieves pdf files and outputs them in a table
> with a link to the file plus the date modified. I'm trying with no
> luck to sort the links starting with newest file. The file path is
> newbusiness/2007. There is a folder for each year. A the top of the
> table is a list of links to each year folder. Below is the code:

[snip]

Please don't post all of your code; just the problem part!

BTW, you don't have to "Exit Function" and "Exit Sub"
just before "End Function" and "End Sub", respectively.

Perhaps the following will help get you on track.

'*
'* Declare Variables
'*
Dim i, j, k
Dim intDLM
Dim dtmDLM
Dim dtmNOW
dtmNOW = Now
Dim arrPDF()
ReDim arrPDF(0)
Dim intPDF
intPDF = 0
Dim strPDF
'*
'* Build array
'*
For Each File in Files
If LCase(ObjFSO.GetExtensionName(File.Name)) = "pdf" Then
dtmDLM = File.DateLastModified
intDLM = 10^10 + DateDiff("s",dtmDLM,dtmNOW)
strPDF = intDLM & "^" & dtmDLM & "^" & File.Name
ReDim Preserve arrPDF(intPDF)
arrPDF(intPDF) = strPDF
intPDF = intPDF + 1
End If
Next
If intPDF = 0 Then
WScript.Echo "No PDFs in " & cFOL
'Response.Write "<li>"No PDFs in " & cFOL
Else
'*
'* Sort array
'*
For i = UBound(arrPDF) - 1 To 0 Step -1
For j = 0 To i
If arrPDF(j) > arrPDF(j+1) Then
k = arrPDF(j+1)
arrPDF(j+1) = arrPDF(j)
arrPDF(j) = k
End If
Next
Next
'*
'* List array
'*
For intPDF = 0 To UBound(arrPDF)
strPDF = Split(arrPDF(intPDF),"^")
WScript.Echo "DateLastModified= " & strPDF(1) & " : " & strPDF(2)
'Response.Write "<li>DateLastModified= " & strPDF(1) & " : " & strPDF(2)
Next
End If

To test it you can add the following lines at the beginning
and save it all to "sortpdfs.vbs" then run it at a command
prompt using "cscript //nologo sortpdfs.vbs" and look at the
results. Change the value of "cFOL" to a folder with PDFs.

Option Explicit
Const cFOL = "C:\Temp"
Dim ObjFSO
Set ObjFSO = CreateObject("Scripting.FileSystemObject")
Dim ObjGFO
Set ObjGFO = ObjFSO.GetFolder(cFOL)
Dim File
Dim Files
Set Files = ObjGFO.Files



Re: Sorting in VBscript by noone

noone
Sat Dec 01 14:51:19 PST 2007

Il giorno Fri, 30 Nov 2007 13:51:26 -0800 (PST), robert.s@att.net ha scritto:

>I have a vbscript that retrieves pdf files and outputs them in a table
>with a link to the file plus the date modified. I'm trying with no
>luck to sort the links starting with newest file. The file path is
>newbusiness/2007. There is a folder for each year. A the top of the
>table is a list of links to each year folder. Below is the code:

why not using dir /od *.pdf /b >sortedlist.txt
Creates a list of pdf's filenames sorted from the most recent.
Then read the name and retrieve its date.
Giovanni.
--
Giovanni Cenati (Aosta, Italy)
Write to user "Reventlov" and domain at katamail com
http://digilander.libero.it/Cenati (Esempi e programmi in VbScript)
--

Re: Sorting in VBscript by Pegasus

Pegasus
Sat Dec 01 16:38:53 PST 2007


"Reventlov" <noone@no.void> wrote in message
news:4751e4d7.5061618@powernews.libero.it...
> Il giorno Fri, 30 Nov 2007 13:51:26 -0800 (PST), robert.s@att.net ha
> scritto:
>
>>I have a vbscript that retrieves pdf files and outputs them in a table
>>with a link to the file plus the date modified. I'm trying with no
>>luck to sort the links starting with newest file. The file path is
>>newbusiness/2007. There is a folder for each year. A the top of the
>>table is a list of links to each year folder. Below is the code:
>
> why not using dir /od *.pdf /b >sortedlist.txt
> Creates a list of pdf's filenames sorted from the most recent.
> Then read the name and retrieve its date.
> Giovanni.

That's an impressive implementation of the KISS principle: To
replace the OP's 450 lines of VB Script code with a single
command!



Re: Sorting in VBscript by McKirahan

McKirahan
Sat Dec 01 16:52:32 PST 2007

"Pegasus (MVP)" <I.can@fly.com> wrote in message
news:OR6s2uHNIHA.6108@TK2MSFTNGP03.phx.gbl...
>
> "Reventlov" <noone@no.void> wrote in message
> news:4751e4d7.5061618@powernews.libero.it...
> > Il giorno Fri, 30 Nov 2007 13:51:26 -0800 (PST), robert.s@att.net ha
> > scritto:
> >
> >>I have a vbscript that retrieves pdf files and outputs them in a table
> >>with a link to the file plus the date modified. I'm trying with no
> >>luck to sort the links starting with newest file. The file path is
> >>newbusiness/2007. There is a folder for each year. A the top of the
> >>table is a list of links to each year folder. Below is the code:
> >
> > why not using dir /od *.pdf /b >sortedlist.txt
> > Creates a list of pdf's filenames sorted from the most recent.
> > Then read the name and retrieve its date.
> > Giovanni.
>
> That's an impressive implementation of the KISS principle: To
> replace the OP's 450 lines of VB Script code with a single
> command!

It doesn't replace all 450 lines -- actually it was only 443 lines.

In fact additional lines will be need to execute the command
as well as opening, reading, and processing the results.

One issue may be parsing the results of the dir command;
especially if subfolders are involved.



Re: Sorting in VBscript by Pegasus

Pegasus
Sun Dec 02 00:49:20 PST 2007


"McKirahan" <News@McKirahan.com> wrote in message
news:bOidnf3Rd4lNnM_anZ2dnUVZ_rqlnZ2d@comcast.com...
> "Pegasus (MVP)" <I.can@fly.com> wrote in message
> news:OR6s2uHNIHA.6108@TK2MSFTNGP03.phx.gbl...
>>
>> "Reventlov" <noone@no.void> wrote in message
>> news:4751e4d7.5061618@powernews.libero.it...
>> > Il giorno Fri, 30 Nov 2007 13:51:26 -0800 (PST), robert.s@att.net ha
>> > scritto:
>> >
>> >>I have a vbscript that retrieves pdf files and outputs them in a table
>> >>with a link to the file plus the date modified. I'm trying with no
>> >>luck to sort the links starting with newest file. The file path is
>> >>newbusiness/2007. There is a folder for each year. A the top of the
>> >>table is a list of links to each year folder. Below is the code:
>> >
>> > why not using dir /od *.pdf /b >sortedlist.txt
>> > Creates a list of pdf's filenames sorted from the most recent.
>> > Then read the name and retrieve its date.
>> > Giovanni.
>>
>> That's an impressive implementation of the KISS principle: To
>> replace the OP's 450 lines of VB Script code with a single
>> command!
>
> It doesn't replace all 450 lines -- actually it was only 443 lines.
>
> In fact additional lines will be need to execute the command
> as well as opening, reading, and processing the results.
>
> One issue may be parsing the results of the dir command;
> especially if subfolders are involved.

I was being facetious. My main objection to the OP's huge post
is his amazing expectation that someone would go to the trouble
of wading through his 450 (sorry: 443) lines of code instead
of him taking the time to show us just the problem section -
a point which you already touched on.



Re: Sorting in VBscript by axtens

axtens
Mon Dec 03 01:24:43 PST 2007

As I'm updating my labels, check out what I've done on sorting at
http://codeaholic.blogspot.com/search/label/sorting

Kind regards,
Bruce.