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

Function nextAvailableFilename

src/shared/utils/fs.ts:527–544  ·  view source on GitHub ↗
(folder: string, prefix: string, suffix = "")

Source from the content-addressed store, hash-verified

525 * @param suffix suffix of the directory/file
526 */
527export function nextAvailableFilename(folder: string, prefix: string, suffix = ""): string {
528 // Set an upper bound on how many attempts we should make in getting a non-existent name.
529 const maxSearchLimit = 128;
530
531 for (let index = 1; index <= maxSearchLimit; index++) {
532 const name = `${prefix}${index}${suffix}`;
533 const fullPath = path.join(folder, name);
534
535 if (!fs.existsSync(fullPath)) {
536 // Name doesn't appear to exist on-disk and thus can be used - return it.
537 return name;
538 }
539 }
540
541 // We hit the search limit, so return {prefix}{index} (eg. mydir1) and allow the extension to
542 // handle the already-exists condition if user doesn't change it manually.
543 return `${prefix}1${suffix}`;
544}
545
546/// Updates the modification time of a file to the current time (if the file exists).
547export function touchFile(filePath: string): void {

Callers 3

flutterScreenshotMethod · 0.90
createDartProjectMethod · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected