file.copyTo() ajoute le symbole interdit ':'

in this case, $sourceFolder.parent returns Null. So, next line is on error due to this.

Did you change all lines?

I got totally the same error as you show,
when i use “Get 4D folder” by execute the copyTo.

Example without any Error (successfully copied file):

C_OBJECT($source;$copy)
$source:=Folder(fk database folder).file("test.html")
$copy:=$source.copyTo(Folder(fk database folder);"test2.html";fk overwrite)

Example with Error:

C_OBJECT($source;$copy)
$source:=Folder(Get 4D folder(Database folder);fk platform path).file("test.html")
$copy:=$source.copyTo(Folder(Get 4D folder(Database folder));"test2.html";fk overwrite)

The thing is in you example, you stay at the same level of directory (inside the dayabase folder).
In my case, I’m moving outside this directory. So, the command

Folder(fk database folder).parent

return a Null value => I’m not able to define the end of the path required to perform the copy.

Hello,

Folder(fk database folder) // Returns a file system path. 
//No code can access elements located above the file system root on the disk (sandboxing).

whereas:

Get 4D folder(Database folder) // always returns a platform path

https://doc.4d.com/4Dv18/4D/18/File-and-folder-object-pathnames.300-4506091.en.html

So :

C_OBJECT($source;$copy)
$source:=Folder(Get 4D folder(Database folder);fk platform path).file("test.html")
//$copy:=$source.copyTo(Folder(Get 4D folder(Database folder));"test2.html";fk overwrite) Missing  fk platform path
$copy:=$source.copyTo(Folder(Get 4D folder(Database folder); fk platform path);"test2.html";fk overwrite) // should work
// or
$copy:=$source.copyTo(Folder(fk database folder);"test2.html";fk overwrite) // should work
1 Like

Hi Guillaume

Thanks, i confirm
when a insert my forgotten “fk platform path”
this works too without any error!

C_OBJECT($source;$copy)
$source:=Folder(Get 4D folder(Database folder);fk platform path).file("test.html")
$copy:=$source.copyTo(Folder(Get 4D folder(Database folder);fk platform path);"test2.html";fk overwrite)

So this error always happens when anywhere in Patrick’s example some forgotten “fk platform path” or any other mixing types of path.

Finally, I change my mind, based on all your contribution :clap:

The follwoing code works:

C_OBJECT($myFile;$copy)
$app:="QS_toolbox"
  //$sourcePath:=Get 4D folder(Database folder)
$sourcePath:=Folder(Get 4D folder(Database folder);fk platform path)
$compilePath_s:=$sourcePath.parent.path+$sourcePath.name
$compilePath:=$compilePath_s+"_build/Base de données compilée/"+$app+".4dbase/"
$codeMirror:=$compilePath_s+"_build/Base de données compilée/"+$app+".4dbase/Resources/codemirror/mode/4d/"

$myFile:=Folder($codeMirror;fk platform path).file("4d_source.js")
$copy:=$myFile.copyTo(Folder($codeMirror;fk platform path);"4d.js";fk overwrite)
$myFile:=Folder($codeMirror).file("4d_source.js").delete()

Now, I have to have a better understanding of this kind of scenarios.

1 Like

You must unsandbox :

$o:=folder(folder(fk data  base folder).platformPath).parent

Hi Vincent,

I got the following error with the syntaxt provided:

La valeur ‘null’ n’est pas prise en charge par ce type d’expression.

Sorry, I’ve omitted the constant*

$o:=folder(folder(fk data  base folder).platformPath; fk platform path).parent

*from my phone :wink:

1 Like

Effectively, constant with these commands seems to be mandatory to get what we want.
Thanks Vincent

And don’t omit the * for a call from a component

If needed :wink:
In my case, it is not, but thanks for the reminder.

Tiens tiens…
Du coup j’ai relu la doc :hot_face: :
« • La sécurité : Aucun code peut accéder aux éléments d’accès situés au-dessus de la racine des filesystem sur disque ( sandboxing ). »
C’est ce qui exclue l’accès à d’autres volumes ?

Bonjour Arnaud,

je pense que Vincent voulais dire que plutôt que faire pas à pas comme je l’ai fait, que cela pouvait aussi se faire de manière moins conventionnelle en utilisant uniquement les ‘nouvelles’ commandes.