1
\$\begingroup\$

I need to list all the files in the res folder from a JavaScript script in cocos2d-x. What would be the most efficient way to do this?

To keep compatibility with Cocos2d-html5 a JavaScript-only solution is most desirable.

\$\endgroup\$
1
\$\begingroup\$

Javascript doesn't have access to the filesystem. This is for security purposes.

However, HTML5 does allow access to a sandbox filesystem. Cocos2D has an implementation of this sandbox access, but it doesn't appear to be official support. It's not too likely that utilizing this sandbox will be something that's cross platform. In this situation, you'll likely have to create platform specific code.

\$\endgroup\$
  • \$\begingroup\$ Currently I know more or less the names of the files I need to access so I keep fishing but this solution generates a lot of errors and is definitely not good for production code... \$\endgroup\$ – Coyote Dec 19 '13 at 20:41
0
\$\begingroup\$

Not sure if this will help, but in the following this file: http://cocos2djs.org/demos/tile-maps I found this construct:

var map = new TMXTiledMap(
    { file: path.join(__dirname, '../resources/TileMaps/iso-test.tmx')})

The github site also has tutorials on using javascript for cocos2d

\$\endgroup\$
  • \$\begingroup\$ Unfortunately it doesn't help. I'm looking for an API to list available files in a folder. I can read any file y name, there is no problem with that. \$\endgroup\$ – Coyote Dec 21 '13 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.