• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Oct 31, 2019 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

1.1K

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
community guidelines
LEGEND ,
Oct 31, 2019 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,

 

^ _ ^

Votes

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
community guidelines
Community Beginner ,
Oct 31, 2019 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.

Votes

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
community guidelines
LEGEND ,
Oct 31, 2019 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,

 

^ _ ^

Votes

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
community guidelines
Community Expert ,
Oct 31, 2019 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>

Votes

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
community guidelines
Community Beginner ,
Nov 01, 2019 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.

Votes

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
community guidelines
Community Expert ,
Nov 02, 2019 Nov 02, 2019

Copy link to clipboard

Copied

LATEST

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

Votes

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
community guidelines
Resources
Documentation