Get date and time in such a way that it can be made part of a
file name:<%=Month(now())&"_"&Day(now())&"_"&Year(now())&"_"&Minute(now())&"_"&Second(now())%>
gives you 7_4_2009_39_47 which may be useful for naming files that are created on-the-fly.
Isolate a file name away from its path or extension or strip a path from a file name or strip characters from database field
(Note: I find this code does it better because it handles both 3 letter and 4 letter file extensions.)
Here is a bit of handy code that I have used over and over for different purposes. See the original code by Scott Campbell. This code is so useful that I am publishing it here for my own convenience, to make it easy to find when I need it again.
Here is an example of what the code can do:
Here it is with a bit of modification as I used it in one of my projects. The first line is to avoid an error due to the fact that "overall" does not have a file extension such as .asp after it.
<%
if NOT x_counterpage = "overall" then
dim strFileName, str3, str3b, strExt
strFileName = x_counterpage 'Getting the filename from our database and setting
the string contents.
intHowLong = Len(strFileName) 'Getting the number of character contained within
the filename.
str3b = intHowLong - 30
str3 = intHowLong - intHowLong + 3 'Subtracting the number of characters then
adding 3. This is effectively removing the filename and leaving only the
extension.
strExt = Right(strFilename, str3b)
'response.write strFileName &"<br>"
'response.write intHowLong &"<br>"
'response.write "str3b" & str3b &"<br>"
'response.write "strExt" & strExt &"<br>"
end if
%>
Here is the same code, used for a different purpose, to tell the script to display a link to an html page if the file extension is .htm or to display an image if not:
<%
dim strFileName, str3, strExt
strFileName = strFieldValue 'Getting the filename from our database and setting
the string contents.
intHowLong = Len(strFileName) 'Getting the number of character contained within
the filename.
str3 = intHowLong - intHowLong + 3 'Subtracting the number of characters then
adding 3. This is effectively removing the filename and leaving only the
extension.
strExt = Right(strFilename, str3) 'Isolating the extension (the last three
characters of strFileName) from the filename.
If strExt = "htm" Then
Response.Write "<a href=javascript:popUp('../horse-show/videos/" & strFileName &
"')><img src=../horse-show/images/video.jpg></a>"
Else
Response.Write("<a href=javascript:popUp('http://quarter-horse-times.com/scripts/showfiles/"
& newStr & "')>" & "<img src=../scripts/showfiles/thumbs/TH_" & newStr & ">")
End If
End IF
Next
Response.Write("</td>")
Next
Response.Write("</tr></table>")
%>
UPDATE: YET ANOTHER WAY I AM USING THIS CODE
This can be used to dynamically calculate the user's folder path and may
reduce the need for manual customization in some of your scripts.
Click here to test and view.
Click here to see how to use it with ASPjpeg
--Lil at horsevu.com
I use
and recommend ASPMaker
| Lewis Moten's code for isolating file extensions, etc., copied from
http://www.planet-source-code.com/vb/scripts/ShowCode.asp?lngWId=4&txtCodeId=6286
'************************************** |