GetDirectoryFromPath

Description

Extracts a filename and directory from an absolute path.

Return value

Absolute path, without the filename. The last character is a backward slash.

Category

System functions

Syntax

GetDirectoryFromPath(path) 

See also

ExpandPath, GetFileFromPath

Parameters

Parameter Description
path
Absolute path (drive, directory, filename, and extension)

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 file name,
  #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 file name</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> --->

Comments