User Guide Cancel

DirectoryRename

 

Description

Renames on-disk or in-memory directory.

Category

System functions

Function Syntax

DirectoryRename(oldPath,newPath)
DirectoryRename(oldPath,newPath)
DirectoryRename(oldPath,newPath)

See Also

DirectoryCreateDirectoryDeleteDirectoryExistsDirectoryList

Usage

Ensure that you have the required permissions to run this function.

History

ColdFusion (2018 release): Renamed the following parameters:

  • path to oldPath
  • newName to newPath

ColdFusion 9: Added this function

Parameters

Parameter

Description

oldPath

Absolute path of the directory to be renamed. Alternatively, you can specify IP address, for example, DirectoryRename("//12.3.123.123/c_drive/test");

newPath

Name with which the directory has to be renamed.

Example

<h2>DirectoryRename Example</h2>
<h3>Enter a directory to rename.</h3>
<cfform action = "directoryRename.cfm" method="post" preservedata="true" >
<label for="renameDirectory">Directory to rename: </label><cfinput required="true" type = "text" id="renameDirectory" name = "renameDirectory">
<br/>
<label for="newName">New Name: </label><cfinput required="true" type="text" id="newName" name = "newName">
<br/>
<input type = "submit" value="submit" name="submit">
</cfform>
<cfif IsDefined("FORM.renameDirectory") and IsDefined("FORM.newName") >
<cfif FORM.renameDirectory is not "" and FORM.newName is not "">
<cfset renameDirectory = FORM.renameDirectory>
<cfset newName = FORM.newName>
<cftry>
<cfset DirectoryRename(renameDirectory,newName)>
<cfoutput><b>Directory #renameDirectory# renamed to newName</b></cfoutput>
<cfcatch>
<b>Error Message:</b><cfoutput>#cfcatch.message#</cfoutput><br/>
<b>Error Detail:</b><cfoutput>#cfcatch.Detail#</cfoutput>
</cfcatch>
</cftry>
</cfif>
</cfif>
<h2>DirectoryRename Example</h2> <h3>Enter a directory to rename.</h3> <cfform action = "directoryRename.cfm" method="post" preservedata="true" > <label for="renameDirectory">Directory to rename: </label><cfinput required="true" type = "text" id="renameDirectory" name = "renameDirectory"> <br/> <label for="newName">New Name: </label><cfinput required="true" type="text" id="newName" name = "newName"> <br/> <input type = "submit" value="submit" name="submit"> </cfform> <cfif IsDefined("FORM.renameDirectory") and IsDefined("FORM.newName") > <cfif FORM.renameDirectory is not "" and FORM.newName is not ""> <cfset renameDirectory = FORM.renameDirectory> <cfset newName = FORM.newName> <cftry> <cfset DirectoryRename(renameDirectory,newName)> <cfoutput><b>Directory #renameDirectory# renamed to newName</b></cfoutput> <cfcatch> <b>Error Message:</b><cfoutput>#cfcatch.message#</cfoutput><br/> <b>Error Detail:</b><cfoutput>#cfcatch.Detail#</cfoutput> </cfcatch> </cftry> </cfif> </cfif>
<h2>DirectoryRename Example</h2> 
<h3>Enter a directory to rename.</h3> 
<cfform action = "directoryRename.cfm" method="post" preservedata="true" > 
<label for="renameDirectory">Directory to rename: </label><cfinput required="true" type = "text" id="renameDirectory" name = "renameDirectory"> 
<br/> 
<label for="newName">New Name: </label><cfinput required="true" type="text" id="newName" name = "newName"> 
<br/> 
<input type = "submit" value="submit" name="submit"> 
</cfform> 

<cfif IsDefined("FORM.renameDirectory") and IsDefined("FORM.newName") > 
<cfif FORM.renameDirectory is not "" and FORM.newName is not ""> 
<cfset renameDirectory = FORM.renameDirectory> 
<cfset newName = FORM.newName> 
<cftry> 
<cfset DirectoryRename(renameDirectory,newName)> 
<cfoutput><b>Directory #renameDirectory# renamed to newName</b></cfoutput> 
<cfcatch> 
<b>Error Message:</b><cfoutput>#cfcatch.message#</cfoutput><br/> 
<b>Error Detail:</b><cfoutput>#cfcatch.Detail#</cfoutput> 
</cfcatch> 
</cftry> 
</cfif> 
</cfif>

Get help faster and easier

New user?