Skip to main content
Inspiring
September 17, 2021
Answered

<CFDIRECTORY action="CREATE"

  • September 17, 2021
  • 1 reply
  • 295 views

Bonjour,

Alors que je l'ai fait de nombreuses fois dans d'autres programmes, cette fois-ci j'ai une erreur :

<cfset DIR=#db_dir# & "#session.site#" & "/" & "_Ouvrages" & "/" & "APED" & "/" & "Auteurs" & "/" & "MOSTARAN">
<cfset DIRB=#DIR# & "/" & "hello">
<CFIF not DirectoryExists(#DIRB#)>
	<CFDIRECTORY action="CREATE" directory="#verifdirb#">
</CFIF>

Voici le message d'erreur :

 An error occurred when performing a file operation create on file http://localhost:8500/SoLivres/_Ouvrages/APED/Auteurs/MOSTARAN/hello.
The cause of this exception was: org.apache.commons.vfs2.FileSystemException: Invalid absolute URI "http://localhost:8500/SoLivres/_Ouvrages/APED/Auteurs/MOSTARAN/hello".. 

Merci d'avance pour votre aide !

Cordialement

This topic has been closed for replies.
Correct answer BKBK
quote

Mais je ne comprends pas pourquoi il faut inialiser une nouvelle variable !

<cfset testDir=DIR & "\" & "myTestDirectory">

alors que juste au dessus on a une variable identique :

<cfset DIRB=#DIR# & "/" & "hello">

Mystère !

Merci pour votre éclairage.


By @ZNB

 

Bonjour @ZNB ,

 

The only difference is that your code creates the directory "hello", whereas mine creates the directory "myTestDirectory". Apart from that, your line of code is essentially identical to mine. 

 

The FileSystemException occurs because the value of the directory attribute in cfdirectory contains db_dir & session.site as part of the directory's absolute path. However, the string db_dir & session.site contains http://localhost:8500. This is an http path, not a file path.

 

You should, in place of  http://localhost:8500, use the corresponding value for file path. It is expandPath(""). That is what the test demonstrates.

1 reply

BKBK
Community Expert
Community Expert
September 18, 2021

You have mixed two protocols: file and http. You should not use http://localhost with cfdirectory if you want to create a directory on the file-system. You should instead use the file's absolute path.

 

The file path that corresponds to http://localhost:8500 is wwwroot. Its absolute path is expandPath("")

 

Hence, the http path 

http://localhost:8500/SoLivres/_Ouvrages/APED/Auteurs/MOSTARAN

corresponds to the file path

expandPath("") & "\" & "soLivres" & "\" & "_Ouvrages" & "\" & "APED" & "\" & "Auteurs" & "\" & "MOSTARAN"

 

Code example for you to test:

<!--- Absolute path--->
<cfset DIR=expandPath("") & "\" & "soLivres" & "\" & "_Ouvrages" & "\" & "APED" & "\" & "Auteurs" & "\" & "MOSTARAN">

<cfset testDir=DIR & "\" & "myTestDirectory">

<!--- If the test directory does not exist, create it --->
<CFIF not DirectoryExists(testDir)>
	<CFDIRECTORY action="CREATE" directory="#testDir#">
</CFIF>

 

 

ZNBAuthor
Inspiring
September 20, 2021

Bonjour,

En effet cela marche !

Mais je ne comprends pas pourquoi il faut inialiser une nouvelle variable !

<cfset testDir=DIR & "\" & "myTestDirectory">

alors que juste au dessus on a une variable identique :

<cfset DIRB=#DIR# & "/" & "hello">

Mystère !

Merci pour votre éclairage.

BKBK
Community Expert
BKBKCommunity ExpertCorrect answer
Community Expert
September 20, 2021
quote

Mais je ne comprends pas pourquoi il faut inialiser une nouvelle variable !

<cfset testDir=DIR & "\" & "myTestDirectory">

alors que juste au dessus on a une variable identique :

<cfset DIRB=#DIR# & "/" & "hello">

Mystère !

Merci pour votre éclairage.


By @ZNB

 

Bonjour @ZNB ,

 

The only difference is that your code creates the directory "hello", whereas mine creates the directory "myTestDirectory". Apart from that, your line of code is essentially identical to mine. 

 

The FileSystemException occurs because the value of the directory attribute in cfdirectory contains db_dir & session.site as part of the directory's absolute path. However, the string db_dir & session.site contains http://localhost:8500. This is an http path, not a file path.

 

You should, in place of  http://localhost:8500, use the corresponding value for file path. It is expandPath(""). That is what the test demonstrates.