Skip to content

Instantly share code, notes, and snippets.

@trevorfoskett
Created November 25, 2019 19:16
Show Gist options
  • Save trevorfoskett/4a653db1cc8372461c8c5dc6758c51ec to your computer and use it in GitHub Desktop.
Save trevorfoskett/4a653db1cc8372461c8c5dc6758c51ec to your computer and use it in GitHub Desktop.
Assigning a unique filename if filename already exists.
var i = 1;
var array = fileName.split('.');
var encryptFileName = `${array[0]}.${array[1]}.tdf3.html`;
while (fs.existsSync(`./encrypt-out/${encryptFileName}`)) {
encryptFileName = `${array[0]} (${i}).${array[1]}.tdf3.html`;
i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment