@@ -443,7 +443,7 @@ define(function (require, exports, module) {
443
443
}
444
444
445
445
/**
446
- * Get the parent directory of a file. If a directory is passed in the directory is returned.
446
+ * Get the parent directory of a file. If a directory is passed, the SAME directory is returned.
447
447
* @param {string } fullPath full path to a file or directory
448
448
* @return {string } Returns the path to the parent directory of a file or the path of a directory,
449
449
* including trailing "/"
@@ -453,8 +453,22 @@ define(function (require, exports, module) {
453
453
}
454
454
455
455
/**
456
- * Get the file name without the extension.
457
- * @param {string } filename File name of a file or directory
456
+ * Get the parent folder of the given file/folder path. Differs from getDirectoryPath() when 'fullPath'
457
+ * is a directory itself: returns its parent instead of the original path. (Note: if you already have a
458
+ * FileSystemEntry, it's faster to use entry.parentPath instead).
459
+ * @param {string } fullPath full path to a file or directory
460
+ * @return {string } Path of containing folder (including trailing "/"); or "" if path was the root
461
+ */
462
+ function getParentPath ( fullPath ) {
463
+ if ( fullPath === "/" ) {
464
+ return "" ;
465
+ }
466
+ return fullPath . substring ( 0 , fullPath . lastIndexOf ( "/" , fullPath . length - 2 ) + 1 ) ;
467
+ }
468
+
469
+ /**
470
+ * Get the file name without the extension. Returns "" if name starts with "."
471
+ * @param {string } filename File name of a file or directory, without preceding path
458
472
* @return {string } Returns the file name without the extension
459
473
*/
460
474
function getFilenameWithoutExtension ( filename ) {
@@ -559,6 +573,7 @@ define(function (require, exports, module) {
559
573
exports . isStaticHtmlFileExt = isStaticHtmlFileExt ;
560
574
exports . isServerHtmlFileExt = isServerHtmlFileExt ;
561
575
exports . getDirectoryPath = getDirectoryPath ;
576
+ exports . getParentPath = getParentPath ;
562
577
exports . getBaseName = getBaseName ;
563
578
exports . getRelativeFilename = getRelativeFilename ;
564
579
exports . getFilenameWithoutExtension = getFilenameWithoutExtension ;
0 commit comments