|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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 & _ " <a href=""" & slot & oFile.Name & """>" & _ oFile.Name & "</a><br>" ElseIf Left(oFile.Name, 1) = "M" Then strMonthly = strMonthly & _ " <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> |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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> |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ASP Programming > convert filenames to a text date in a hyperlink |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|