Created
March 21, 2024 21:05
-
-
Save cassidoo/c780a0045acb6b2c5b0b51b99ebda8b0 to your computer and use it in GitHub Desktop.
A script for a Tauri application to iterate over files and generate new file names and not overwrite old ones
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { BaseDirectory, exists } = window.__TAURI__.fs; | |
async function doesFileExist(fileName) { | |
let fileExists = await exists(fileName + ".pdf", { | |
baseDir: BaseDirectory.Download, | |
}); | |
let fileCounter = 0; | |
while (fileExists) { | |
fileCounter++; | |
fileExists = await exists(fileName + `-${fileCounter}.pdf`, { | |
baseDir: BaseDirectory.Download, | |
}); | |
} | |
return fileCounter > 0 ? fileName + `-${fileCounter}` : fileName; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment