ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 27th, 2003, 11:02 AM
blodefood blodefood is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 37 blodefood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 36 m 15 sec
Reputation Power: 6
Question convert filenames to a text date in a hyperlink

I have this code that displays filenames from a folder according to the first character of the filename.

I need to parse the filename W20031024-ID01.xls or M20031024-ID01.xls so that the text in the hyperlink displays as a date. Note that I can change the file naming conventions if that would make it easier.

e.g. October 24, 2003

I trust I have commented the code adequately.

Would appreciate some assistance. Thanks.

<%
dim strWeekly, strMonthly
strPath = "D://Wwwroot/test/newfolder/ID01/"

dim oFS, oFile, oFolder, oFolderContents, slot, varname

'slot corrects a path discrepency on the testing server
'it will be removed once it goes on the live server

slot="ID01/"
varname=left(oFile,1)

Set oFS = CreateObject("Scripting.FileSystemObject")

Set oFolder = oFS.getFolder(strPath)


For Each oFile In oFolder.files
If Left(oFile.Name, 1) = "W" Then
strWeekly = strWeekly & _
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=""" & slot & oFile.Name & """>" & _
oFile.Name & "</a><br>"
ElseIf Left(oFile.Name, 1) = "M" Then
strMonthly = strMonthly & _
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href=""" & slot & oFile.Name & """>" & _
oFile.Name & "</a><br>"
End If
Next

'after this is complete we will parse the filenames to English

%>

And this in the body of the document to display filenames in their appropriate columns in the table.

<td><% = strWeekly%></td>
<td><% = strMonthly%></td>

Reply With Quote
  #2  
Old October 27th, 2003, 03:54 PM
kkong's Avatar
kkong kkong is offline
Monkey Magic
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2002
Location: UK
Posts: 103 kkong User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to kkong
Hi,

this should do the trick.

Code:

Dim lnNum
Dim lnDay
Dim lnMonth
Dim lnYear

lnNum = "20031023"

lnYear = left(lnNum,4)
lnMonth = mid(lnnum,5,2)
lnDay = mid(lnnum,7,2)

Response.Write (MonthName(lnMonth) & " " & lnDay & ", " & lnYear)


Kong.

Reply With Quote
  #3  
Old October 28th, 2003, 02:00 PM
blodefood blodefood is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Sep 2003
Location: Canada
Posts: 37 blodefood User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 5 h 36 m 15 sec
Reputation Power: 6
Thanks.

I wound up using this from someone else after a fair amount of adaptation.

blodefood

_____________

<%
dim strWeekly, strMonthly
dim strFileName, dtmDate
dim oFS, oFile, oFolder, oFolderContents, slot, varname
dim Monthnamey, Dayy, Yeary
'corrects path discrepency on test server
slot="ID01/"
'for now to display the ID number
slot2="ID01"
'the first char of the filename
varname=left(oFile,1)

'the path will be replaced with a parameter from the login screen
'once the functions in notes below are created and working properly
strPath = "D://Wwwroot/test/newfolder/ID01/"

'Create the filesystem object
Set oFS = CreateObject("Scripting.FileSystemObject")
'get the files named in strpath
Set oFolder = oFS.getFolder(strPath)

For Each oFile In oFolder.files
' below are descriptive but do not use reserved words
Monthnamey = Monthname(Mid(oFile.Name, 6, 2))
Dayy = Mid(oFile.Name, 8, 2)
Yeary = Mid(oFile.Name, 2, 4)

'the filename starts with M or W followed by the date a hyphen and ID number
'format the date from yyyymmdd start at 2 and get 4 to make year
'start at 5 and get 2 to make month and use the name of the month
'start at 7 and get 2 to make day

'sort the files by first char, and display in hyperlink
If Left(oFile.Name, 1) = "W" Then
strWeekly = strWeekly & _
" <a href=""" & slot & oFile.Name & """>" & _
Monthnamey & " " & Dayy & " " & Yeary & "</a><br>"
ElseIf Left(oFile.Name, 1) = "M" Then
strMonthly = strMonthly & _
" <a href=""" & slot & oFile.Name & """>" & _
Monthnamey & " " & Dayy & " " & Yeary & "</a><br>"
End If
Next
%>

and in the body --

<td><% = strWeekly%></td>
<td><% = strMonthly%></td>

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > convert filenames to a text date in a hyperlink


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT