export async function getUniqueFileName()

in src/utils/fsUtils.ts [13:32]


    export async function getUniqueFileName(folderPath: string, prefix: string, suffix?: string): Promise<string> {
        let count: number = 0;
        const maxCount: number = 1024;

        while (count < maxCount) {
            const fullFileName: string = `${prefix}${count === 0 ? '' : `-${count}`}${suffix}`;

            const fullPath: string = path.join(folderPath, fullFileName);

            const pathExists: boolean = await fse.pathExists(fullPath);
            const editorExists: boolean = workspace.textDocuments.some((doc: TextDocument) => isPathEqual(doc.uri.fsPath, fullPath));
            if (!pathExists && !editorExists) {
                return fullFileName;
            }

            count += 1;
        }

        throw new Error(localize('failedUnique', 'Failed to find unique name for new file.'));
    }