Whatever message this page gives is out now! Go check it out!

GetDirectoryFromPath

Last update:
May 18, 2026

Description

Extracts a directory from an absolute on-disk or in-memory path.

Returns

Absolute path, without the filename. The last character is a forward or backward slash, depending on the operating system.

Category

Function syntax

GetDirectoryFromPath(path)

See also

Parameters

Parameter
Description
path
Absolute on-disk or in-memory path.

Usage

Example

<h3>GetDirectoryFromPath Example</h3> 
 <cfset thisPath = ExpandPath("*.*")> 
 <cfset thisDirectory = GetDirectoryFromPath(thisPath)> 
 <cfoutput> 
 The current directory is: #GetDirectoryFromPath(thisPath)# 
 <cfif IsDefined("FORM.yourFile")> 
 <cfif FORM.yourFile is not ""> 
 <cfset yourFile = FORM.yourFile> 
 <cfif FileExists(ExpandPath(yourfile))> 
 <p>Your file exists in this directory. You entered the correct filename, 
 #GetFileFromPath("#thisPath#/#yourfile#")# 
 <cfelse> 
 <p>Your file was not found in this directory: 
 <br>Here is a list of the other files in this directory: 
 <!--- use cfdirectory show directory, order by name & size ---> 
 <cfdirectory directory = "#thisDirectory#" 
 name = "myDirectory" SORT = "name ASC, size DESC"> 
 <!--- Output the contents of the cfdirectory as a CFTABLE ---> 
 <cftable query = "myDirectory"> 
 <cfcol header = "NAME:" text = "#Name#"> 
 <cfcol header = "SIZE:" text = "#Size#"> 
 </cftable> 
 </cfif> 
 </cfif> 
 <cfelse> 
 <H3>Please enter a filename</H3> 
 </cfif> 
 </cfoutput> 
 <form action="getdirectoryfrompath.cfm" METHOD="post"> 
 <H3>Enter the name of a file in this directory <I><FONT SIZE="-1"> 
 (try expandpath.cfm)</FONT></I></H3> 
 <input type="Text" NAME="yourFile"> 
 <input type="Submit" NAME=""> 
 </form> --->

Share this page

Was this page helpful?
We're glad. Tell us how this page helped.
We're sorry. Can you tell us what didn't work for you?
Thank you for your feedback. Your response will help improve this page.

On this page