How To The Write `directoryRename( oldPath, newPath )` Function In ColdFusion?
Description:-
This is used to rename a directory on disk or in memory if you have have the required permissions to run this function.
directoryRename( oldPath, newPath );
Attributes:-
oldPath:-
-
This is a required attribute, and the name of the old directory is to be renamed on an absolute on-disk or in-memory location. Alternatively, you can specify the IP address as in the bellow example:directoryRename( "//192.168.0.1/new_disc/test", "" );
newPath:-
This is a required attribute, and the name of the new directory is to be newly renamed on an absolute on-disk or in-memory location. Alternatively, you can specify the IP address as in the bellow example:directoryRename( "", "//192.168.0.1/new_disc/test" );
Example:-
In this example, we will rename this d:\files\documents
directory to d:\files\tests
in Windows and check if this is created or not.
<cfscript>
if ( !directoryExists( "d:\files\documents" ) ){
directoryCreate( "d:\files\documents" );
}
writeOutput( "Before Rename old: #directoryExists( "d:\files\documents" )#" );
writeOutput( "Before Rename new: #directoryExists( "d:\files\tests" )#" );
directoryRename( "d:\files\documents", "d:\files\tests" );
writeOutput( "After Rename old: #directoryExists( "d:\files\documents" )#" );
writeOutput( "After Rename new: #directoryExists( "d:\files\tests" )#" );
</cfscript>
Result:-
Before Rename old: YES
Before Rename new: NO
After Rename old: NO
After Rename new: YES
In our system, we create tis d:\files\documents
directory fist then check if our old and new directories are exist or not as per result our old one exist but new one is not, after rename operation we also check which one exist now, as per result old one is not exist but newly rename directory is exist now.