path
Class
The module provides utilities for working with file and directory paths
Index
Methods
join
Join strings to be a path.extname
Get the ext name of a path including '.', like '.png'.mainFileName
Get the main name of a file namebasename
Get the file name of a file path.dirname
Get dirname of a file path.changeExtname
Change 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
pathStr
String
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
fileName
String
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
pathStr
String
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"