Skip to content

Instantly share code, notes, and snippets.

@trevorfoskett
Created November 22, 2019 07:20
Show Gist options
  • Save trevorfoskett/8112ee59182321501f9244e3da4a975c to your computer and use it in GitHub Desktop.
Save trevorfoskett/8112ee59182321501f9244e3da4a975c to your computer and use it in GitHub Desktop.
Check if filename exists and if so, count up for files of same name.
var i = 1;
var array = fileName.split('.');
var decryptFileName = `${array[0]}.${array[1]}`;
while (fs.existsSync(`./decrypt-out/${decryptFileName}`)) {
decryptFileName = `${array[0]} (${i}).${array[1]}`;
i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment