File Commands
The File Functions allow your templates to be aware of thier own web and file paths. If an image does not exist, load a different one. There are 8 functions in this category.

DirectoryExists()
Usage: DirectoryExists(absolute_path)
Description: Use DirectoryExists() to determine whether a directory exists on the server.
See Example
Cut and past this code into your own template, or view the live version Here.

<!--- DirectoryExists(absolute_path)

Use DirectoryExists() to determine whether a directory exists on the server.

It is good to check whether the directory exists before using tags like CFFILE.--->

<cfset GoodDirectory = getdirectoryfrompath(expandpath('*.*'))>
<cfset BogusDirectory = "z:\wwwroot\bogusfolder\">

<cfoutput>

<cfif DirectoryExists(GoodDirectory)>
Yes, #GoodDirectory# exists on the server.
<cfelse>
No, #GoodDirectory# does not exist on the server.
</cfif>

<hr>

<cfif DirectoryExists(BogusDirectory)>
Yes, #BogusDirectory# exists on the server.
<cfelse>
No, #BogusDirectory# does not exist on the server.
</cfif>

</cfoutput>

ExpandPath()
Usage: ExpandPath(relative_path)
Description: ExpandPath() returns the fully qualified path for the "relative" path you
provide.
See Example

<!---
ExpandPath(relative_path)

ExpandPath() returns the fully qualified path
for the "relative" path you provide.

Using "*.*" as the relative_path paramater
will cause ExpandPath to return the path to
the template containing the function.
--->

<cfoutput>
Server Path to this file:<br>
#ExpandPath("*.*")# <br><br>


Server path to the directory above this file:<br>
#ExpandPath("../")# <br><br>
</cfoutput>

FileExists()
Usage: FileExists(absolute_path)
Description: Use FileExists() to determine that a file exists on the server.
See Example

<!---
FileExists(absolute_path)

Use FileExists() to determine
that a file exists on the server.

It is good to check whether the directory exists
before using tags like CFFILE.
--->

<cfset FileName = GetFileFromPath(GetCurrentTemplatePath())>
<cfset BogusFileName = "bogusfile.cfm">
<cfset FilePath= getdirectoryfrompath(expandpath('*.*'))>

<cfoutput>

<cfif FileExists(#FilePath#&#FileName#)>
Yes, #FileName# exists on the server.
<cfelse>
No, #GoodFile# does not exist on the server.
</cfif>

<hr>

<cfif FileExists(#FilePath#&#BogusFileName#)>
Yes, #BogusFileName# exists on the server.
<cfelse>
No, #BogusFileName# does not exist on the server.
</cfif>

</cfoutput>

GetBaseTemplatePath()
Usage: GetBaseTemplatePath()
Description: GetBaseTemplatePath() returns the full path to the "top level" template.
See Example

<!---
GetBaseTemplatePath()

GetBaseTemplatePath() returns the full path to the "top level" template.
(see GetCurrentTemplatePath)
--->

<cfoutput>

The Base Template Path of this file is:<br>
#GetBaseTemplatePath()#

</cfoutput>

<!---Remove this comment to see how GetCurrentTemplatePath() differs

<cfinclude template="GetCurrentTemplatePath.cfm">

--->

GetCurrentTemplatePath()
Usage: GetCurrentTemplatePath()
Description: GetCurrentTemplatePath() retains it's path info even if itis "Included" into
another template.
See Example

<!---
GetCurrentTemplatePath()

GetCurrentTemplatePath() retains it's path info even if it
is "Included" into another template. (See GetBaseTemplatePath)
--->

<cfoutput>

The Current Template Path of this file is:<br>
#GetCurrentTemplatePath()#

</cfoutput>

GetDirectoryFromPath()
Usage: GetDirectoryFromPath(path)
Description: GetDirectoryFromPath() Supplies the "Path" Portion of the Fully Qualified
Path.
See Example

<!---
GetDirectoryFromPath(path)

GetDirectoryFromPath() Supplies the "Path"
Portion of the Fully Qualified Path.
--->

<cfset FullyQualifiedPath = GetBaseTemplatePath()>

<cfoutput>

The Path to this file is:<br>
#GetDirectoryFromPath(FullyQualifiedPath)#

</cfoutput>

GetFileFromPath()
Usage: GetFileFromPath(path)
Description: GetFileFromPath() Supplies the "File" Portion of the Fully Qualified Path.
See Example

<!---
GetFileFromPath(path)

GetFileFromPath() Supplies the "File"
Portion of the Fully Qualified Path.
--->

<cfset FullyQualifiedPath = GetBaseTemplatePath()>

<cfoutput>

The Name of this file is:<br>
#GetFileFromPath(FullyQualifiedPath)#

</cfoutput>

GetTemplatePath()
Usage: GetTemplatePath()
Description: GetTemplatePath() returns the full path to the template.
See Example

<!---
GetTemplatePath()

GetTemplatePath() returns the full path to the template.
This function has been "deprecated" so you should use
GetBaseTemplatePath() instead.
--->

<cfoutput>

The Template Path of this file is:<br>
#GetTemplatePath()#

</cfoutput>

.