我试图从谷歌寻找答案,但失败了。
我对python很熟悉,在其中我们可以通过“os.path.sep”检查平台特定的目录分隔符。
XPCOM组件中是否有某种方法或某些常量可以指示路径分隔符?
或者有没有办法标准化特定于平台的路径?
例如用户在window下输入文件路径:C:/path1/path2/test.txt
如果我不使路径平台有效,则使用 nsILocalFile::initWithPath 将引发异常。有效路径应为“C:\path1\path2\test.txt”。所以我想知道有没有办法使路径有效并可以初始化 nsILocalFile。
最佳答案
/**
* Returns file path separator under current OS
*/
function getPathSeparator()
{
var profD = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).
get("ProfD", Components.interfaces.nsIFile);
profD.append("abc");
profD.append("abc");
var length = profD.path.length;
return profD.path.substr(length-("abc".length)-1,1);
}
关于javascript - 如何检查XPCOM组件中的目录分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5814143/