Highlighted

directoryCreate() throws error even after ensuring it doesn't exist

Community Beginner ,
Oct 31, 2019

Copy link to clipboard

Copied

<cfif not directoryExists(arguments.dirPath)>
	<cfset directoryCreate(arguments.dirPath)>
</cfif>

Even after checking that the directory doesn't exist, directoryCreate() fails with:

Message:	The specified directory {directoryPath} could not be created. 
Detail:	The most likely cause of this error is that {directoryPath} already exists on your file system.

Ultimately, I want to delete it to quickly clear all files, then recreate it.

I can instead loop through the directory to delete the files, but removing the directory altogether does the job when it's not being weird about whether or not it exists.

TOPICS
Advanced techniques, Getting started

Views

961

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

directoryCreate() throws error even after ensuring it doesn't exist

Community Beginner ,
Oct 31, 2019

Copy link to clipboard

Copied

<cfif not directoryExists(arguments.dirPath)>
	<cfset directoryCreate(arguments.dirPath)>
</cfif>

Even after checking that the directory doesn't exist, directoryCreate() fails with:

Message:	The specified directory {directoryPath} could not be created. 
Detail:	The most likely cause of this error is that {directoryPath} already exists on your file system.

Ultimately, I want to delete it to quickly clear all files, then recreate it.

I can instead loop through the directory to delete the files, but removing the directory altogether does the job when it's not being weird about whether or not it exists.

TOPICS
Advanced techniques, Getting started

Views

962

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Oct 31, 2019 0
LEGEND ,
Oct 31, 2019

Copy link to clipboard

Copied

What is the value of arguments.dirPath?  Is it something like "F:\path\to\directory"?  Or is it "/path/to/directory"?  The first should work, the second should not.

 

Alternately, you can use an IP address: "//12.12.12.12/path/to/directory".

 

V/r,

 

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 31, 2019 0
Community Beginner ,
Oct 31, 2019

Copy link to clipboard

Copied

Using the first - N:\folder1\folder2\etc\.

It seems to work intermittently.

I can nix the <cfif> and throw a try/catch around it with an empty catch block. That ultimately does what I want, but I'm thinking I shouldn't have to resort to that.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 31, 2019 0
LEGEND ,
Oct 31, 2019

Copy link to clipboard

Copied

Yeah, I know it just _feels_ hackish.. but probably the best way to work around it.

 

V/r,

 

^ _ ^

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 31, 2019 0
Adobe Community Professional ,
Oct 31, 2019

Copy link to clipboard

Copied

Myka, ColdFusion may be right. It just might be that, once in a while, the wrong value of directory path is passed as an argument to the function.

You should test with:

<cftry>
<cfif not directoryExists(arguments.dirPath)>      
    <cfset directoryCreate(arguments.dirPath)>
</cfif>
<cfcatch type="any">
    <cfdump var="#arguments#">
</cfcatch>
</cftry>

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Oct 31, 2019 0
Community Beginner ,
Nov 01, 2019

Copy link to clipboard

Copied

Unfortunately, I was working with the same directory the entire time. And I passed the same variable to the directoryExists() and directoryCreate(). That in itself should be consistent, but it was intermittent.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 01, 2019 0
BKBK LATEST
Adobe Community Professional ,
Nov 02, 2019

Copy link to clipboard

Copied

Myka wrote:

Ultimately, I want to delete it to quickly clear all files, then recreate it.

 

As I said elsewhere in this forum. it is advisable in this situation to use named locks

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Nov 02, 2019 0