fileSearch & fileRandom Limitations

1145
2
03-15-2021 12:28 PM
DevinLavigne
Occasional Contributor III

I discovered today that fileSearch and fileRandom will not return a result if there is a space in the path.

For example print(fileRandom(/Project Name/*.*)) will not work but print(fileRandom(/DifferentProjectName/*.*)) does. I renamed my project but it broke a ton of references in other places. Is there a way to get around this limitation?   or chr(32)...something like that? 

2 Replies
DavidWasserman
Occasional Contributor III

It is incredible how much of rule design is just filename management. 

David Wasserman, AICP
0 Kudos
CherylLau
Esri Regular Contributor

This is actually not a bug.  Whitespace inside the searchQuery string in fileSearch/filesSearch indicates AND in the query.  Using whitespace, two or more queries can be AND-ed.  See the last example in the doc.

https://doc.arcgis.com/en/cityengine/latest/cga/cga-file-search-function.htm

The same applies to other functions which use fileSearchassetApproxRatio, assetApproxSize, assetBestRatio, assetBestSize, assetFitSizefileRandomimageApproxRatioimageBestRatio


In order to put whitespace into a filepath, use single quotes:

 

filesSearch("'Wall Textures/*.png'")

 

 

Alternatively, the escape characters \s and \x20 also work to replace a space.  Note that an extra backslash is needed so the cga compiler interprets it correctly (instead of as a normal backslash).

 

filesSearch("Wall\\sTextures/*.png")
filesSearch("Wall\\x20Textures/*.png")

 

 

0 Kudos