path Class
The module provides utilities for working with file and directory paths
Index
Methods
joinJoin strings to be a path.extnameGet the ext name of a path including '.', like '.png'.mainFileNameGet the main name of a file namebasenameGet the file name of a file path.dirnameGet dirname of a file path.changeExtnameChange extname of a file path.
Details
Methods
join
Join strings to be a path.
| meta | description |
|---|---|
| Returns | String |
| Defined in | cocos2d/core/utils/CCPath.js:43 |
Examples
------------------------------
cc.path.join("a", "b.png"); //-->"a/b.png"
cc.path.join("a", "b", "c.png"); //-->"a/b/c.png"
cc.path.join("a", "b"); //-->"a/b"
cc.path.join("a", "b", "/"); //-->"a/b/"
cc.path.join("a", "b/", "/"); //-->"a/b/"
extname
Get the ext name of a path including '.', like '.png'.
| meta | description |
|---|---|
| Returns | Any |
| Defined in | cocos2d/core/utils/CCPath.js:59 |
Parameters
pathStrString
Examples
---------------------------
cc.path.extname("a/b.png"); //-->".png"
cc.path.extname("a/b.png?a=1&b=2"); //-->".png"
cc.path.extname("a/b"); //-->null
cc.path.extname("a/b?a=1&b=2"); //-->null
mainFileName
Get the main name of a file name
| meta | description |
|---|---|
| Returns | String |
| Defined in | cocos2d/core/utils/CCPath.js:72 |
Parameters
fileNameString
basename
Get the file name of a file path.
| meta | description |
|---|---|
| Returns | Any |
| Defined in | cocos2d/core/utils/CCPath.js:89 |
Parameters
Examples
---------------------------------
cc.path.basename("a/b.png"); //-->"b.png"
cc.path.basename("a/b.png?a=1&b=2"); //-->"b.png"
cc.path.basename("a/b.png", ".png"); //-->"b"
cc.path.basename("a/b.png?a=1&b=2", ".png"); //-->"b"
cc.path.basename("a/b.png", ".txt"); //-->"b.png"
dirname
Get dirname of a file path.
| meta | description |
|---|---|
| Returns | Any |
| Defined in | cocos2d/core/utils/CCPath.js:110 |
Parameters
pathStrString
Examples
---------------------------------
* unix
cc.path.driname("a/b/c.png"); //-->"a/b"
cc.path.driname("a/b/c.png?a=1&b=2"); //-->"a/b"
cc.path.dirname("a/b/"); //-->"a/b"
cc.path.dirname("c.png"); //-->""
* windows
cc.path.driname("a\\b\\c.png"); //-->"a\b"
cc.path.driname("a\\b\\c.png?a=1&b=2"); //-->"a\b"
changeExtname
Change extname of a file path.
| meta | description |
|---|---|
| Returns | String |
| Defined in | cocos2d/core/utils/CCPath.js:123 |
Parameters
Examples
---------------------------------
cc.path.changeExtname("a/b.png", ".plist"); //-->"a/b.plist"
cc.path.changeExtname("a/b.png?a=1&b=2", ".plist"); //-->"a/b.plist?a=1&b=2"