(folder: string, prefix: string, suffix = "")
| 525 | * @param suffix suffix of the directory/file |
| 526 | */ |
| 527 | export 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). |
| 547 | export function touchFile(filePath: string): void { |
no outgoing calls
no test coverage detected