Skip to content

Instantly share code, notes, and snippets.

@trevorfoskett
Created November 25, 2019 19:17
Show Gist options
  • Save trevorfoskett/b3842b7c5d1c00fca9da6fa08b71f8c9 to your computer and use it in GitHub Desktop.
Save trevorfoskett/b3842b7c5d1c00fca9da6fa08b71f8c9 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