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

<CFDIRECTORY action="CREATE"

Contributor ,
Sep 17, 2021 Sep 17, 2021

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

TOPICS
Database access , Server administration
233
Translate
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

correct answers 1 Correct answer

Community Expert , Sep 20, 2021 Sep 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 o

...
Translate
Community Expert ,
Sep 18, 2021 Sep 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>

 

 

Translate
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
Contributor ,
Sep 20, 2021 Sep 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.

Translate
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 ,
Sep 20, 2021 Sep 20, 2021
LATEST
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.

Translate
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