Classic ASP Active Server Pages Examples, code, tutorials, scriptsGet 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:

/home/saddle_bridle_racks/asp/contact.asp -- this is a file path or can be a file path in a database field
41 - the total number of characters in the string above
str3b is 11 or the total number of characters in the filename without the path (contact.asp)
strExt - is the file name isolated from the path contact.asp

/home/saddle_bridle_racks/asp/Default.asp
Default.asp


/home/saddle_bridle_racks/asp/counter.asp
counter.asp


/home/saddle_bridle_racks/asp/PRODUCTSBlist.asp
PRODUCTSBlist.asp


/home/saddle_bridle_racks/asp/orderinfo.asp
orderinfo.asp
 

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

 

 '**************************************
' for :File/Path/Extension Stripping
'**************************************
Copyright (c) 1999, Lewis Moten. All rights reserved.
'**************************************
' Name: File/Path/Extension Stripping
' Description:These routines can strip a
' file name from a path, a directory from
' a path, and an extension from a path. Th
' ey can also determine the parent directo
' ry path. They are fairly simple routines
' that I use in misc. places.
' By: Lewis E. Moten III
'
'
' Inputs:None
'
' Returns:None
'
'Assumes:None
'
'Side Effects:None
'This code is copyrighted and has limite
' d warranties.
'Please see http://www.Planet-Source-Cod
' e.com/xq/ASP/txtCodeId.6286/lngWId.4/qx/
' vb/scripts/ShowCode.htm
'for details.
'**************************************

'---------------------------------------
' ---------------------------------------
Function ParentDirectory(ByVal asDirectory)
If Len(asDirectory) = 0 Then Exit Function
asDirectory = Replace(asDirectory, "/", "\")
If Right(asDirectory, 1) = "\" Then
asDirectory = Left(asDirectory, Len(asDirectory) - 1)
End If
If asDirectory = "" Then Exit Function
If InStr(1, asDirectory, "\") = 0 Then Exit Function
asDirectory = Left(asDirectory, InStrRev(asDirectory, "\"))
ParentDirectory = asDirectory
End Function
'---------------------------------------
' ---------------------------------------
Function CurrentDirectory()
CurrentDirectory = StripDirectory(Request.ServerVariables("PATH_TRANSLATED"))
' CurrentDirectory = Server.MapPath("/")
'
End Function
'---------------------------------------
' ---------------------------------------
Function StripDirectory(ByVal asPath)
If asPath = "" Then Exit Function
asPath = Replace(asPath, "/", "\")
If InStr(1, asPath, "\") = 0 Then Exit Function
asPath = Left(asPath, InStrRev(asPath, "\"))
StripDirectory = asPath
End Function
'---------------------------------------
' ---------------------------------------
Function StripFileName(ByVal asPath)
If asPath = "" Then Exit Function
asPath = Replace(asPath, "/", "\")
If InStr(asPath, "\") = 0 Then Exit Function
If Right(asPath, 1) = "\" Then Exit Function

StripFileName = Right(asPath, Len(asPath) - InStrRev(asPath, "\"))
End Function
'---------------------------------------
' ---------------------------------------
Function StripFileExt(sFileName)' works for both 3 letter and 4 letter file extensions
If sFileName = "" Then Exit Function
If InStr(1, sFileName, ".") = 0 Then Exit Function
StripFileExt = Right(sFileName, Len(sFileName) - InStrRev(sFileName, ".") + 1)
End Function
'---------------------------------------
' ---------------------------------------

 

ASP Examples Menu of Active Server Pages scripts code Classic ASP

Classic ASP Active Server Pages Examples, code, tutorials, scriptsASP Examples Menu (below*)



Active Server Pages | ASP | Scripts | Tutorials | Code | Web Programming | Examples
Active Server Pages ASP code examples, tutorials, and snippets for use in Programming interactive websites.

NOTE: Recently changed hosting and url so some demos aren't working now because I haven't updated pathing; if you find omissions or errors let me know.
 

*

Multiple records per row with paging

Display multiple records per row

Get ID of newly inserted record, Classic ASP, Access Database

Javascript timer with ASP to keep track of time expired until login expires / timeout session is up

Multiple Javascript event functions triggered from single form onsubmit

Get Querystring key names along with querystring variables

ASP Youtube Downloader  Version FOUR
All ASP code. Allows user client side downloads of Youtube videos. You have the option to allow files to be saved directly to your site also.

ASP/PHP video downloader (Works better than ASP for large files)

Use ASP to dynamically parse a Youtube XML playlist to render to html.

Zip up an archive file of your site for backup if you need to restore website with ASP and free Zip Component.

Zip all files in a folder into an archive or backup file dynamically by specific file extension.

Sanitize or clean price cost field for database insertion or display.

Javascript image dimensions and image file size preview.

Put recordset into array, assign keys to the records then use record associated with specific array key as a variable elsewhere.

Access Database Interface Generator Wizard to read your table and field names and to create a table display.

Combining dropdown selection box menu with dynamic ASP database page.

How to redirect user to original page they tried to view before logging, after they are logged in.

Previous/Current/Next Records, or Buddy Ring Script

Custom ASP 404 page not found error script sends visitors to virtual folders

ASP Example: Combine ASP with Javascript for popup windows
dynamically sized to image dimensions.

ASP Example: How to use ASPJPEG to create thumbnails
Click for free Highly recommended thumbnailer for which you don't need Server access

ASPjpeg: How to re-scale aspect ratio of thumbnails by height instead of width.

ASP Example: What if your host has an older version of ASPJPEG that doesn't support gifs?

Using inline frames as "dynamic includes" (offline for updating)

Select Count Distinct Records for Access Database

Upload Image to folder and insert filename into database

Get date in such a way that it can be made part of a file name

Isolate a file name away from its path or extension or strip a path from a file name or strip characters from database field

User-customized on-the-fly stylesheet css files

Enhanced Page Hits Counter (also counts downloads and menu link hits)

Loop through array and compare to string with select case

Aphabetical Paging for your ASP scripts

Web Wiz Guide's Site Searcher Script modified as a file content indexer

Let Users Select How Many Records to View

Access Database for your PayPal IPN scripts

Miscellaneous collected code

You don't have to be a genius, just persistent, to write original Active Server Pages scripts

Software Recommendation: bare_bones_no_bells_and_whistles_asp_code_generator_database_interface_maker

--Lil at gmail.com