How To The Write `directoryCreate( path )` Function In ColdFusion?
Description:-
This is used to create a directory on disk or in memory.
directoryCreate( path );
Attributes:-
path:- This is a required attribute, the path of a directory to be created on an absolute on-disk or in-memory location. Alternatively, you can specify the IP address as in the bellow example:directoryCreate( "//192.168.0.1/new_disc/test" );
Example:-
In this example, we will create this d:\files\documents directory in Windows and check if this is created or not.
<cfscript>
    writeOutput( "Before creation: #directoryExists( "d:\files\documents" )#" );
    if ( !directoryExists( "d:\files\documents" ) ){
        writeOutput( directoryCreate( "d:\files\documents" ) );
    }
    writeOutput( "After creation: #directoryExists( "d:\files\documents" )#" );
</cfscript>
Result:-
Before creation: No
After creation: Yes
In our system, this d:\files\documents directory did not exist before; that’s why it returned false before when we checked. But after creating this directory, we checked again, and this time, it shows as true as this d:\files\documents directory exists now.
