MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / findCommonAncestorFolder

Function findCommonAncestorFolder

src/shared/utils/fs.ts:107–130  ·  view source on GitHub ↗
(folderPaths: string[])

Source from the content-addressed store, hash-verified

105}
106
107export function findCommonAncestorFolder(folderPaths: string[]): string | undefined {
108 if (!folderPaths.length)
109 return undefined;
110
111 const commonAncestorSegments = folderPaths[0].split(path.sep);
112 for (const folderPath of folderPaths.slice(1)) {
113 const pathSegments = folderPath.split(path.sep);
114 for (let i = 0; i < Math.min(commonAncestorSegments.length, pathSegments.length); i++) {
115 if (commonAncestorSegments[i] !== pathSegments[i]) {
116 commonAncestorSegments.splice(i);
117 break;
118 }
119 }
120 if (commonAncestorSegments.length > pathSegments.length) {
121 commonAncestorSegments.splice(pathSegments.length);
122 }
123 }
124
125 // If we got up to the root, consider that not a match.
126 if (commonAncestorSegments.length <= 1)
127 return undefined;
128
129 return commonAncestorSegments.join(path.sep);
130}
131
132export async function getChildFolders(logger: Logger, parent: string, options?: { allowBin?: boolean; allowCache?: boolean }): Promise<string[]> {
133 if (!fs.existsSync(parent))

Callers 2

fs.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected