Skip to content

Instantly share code, notes, and snippets.

@dgibson666
Created January 5, 2017 14:44
Show Gist options
  • Save dgibson666/dc2e5b583b4988b1b92935c4c6ca793f to your computer and use it in GitHub Desktop.
Save dgibson666/dc2e5b583b4988b1b92935c4c6ca793f to your computer and use it in GitHub Desktop.
Create Valid Filename UDF
// CONVERT A STRING TO A VALID FILENAME
function CreateFileName(string){
var str=Trim(string);
// replace invalid filename characters: /\:*?"<>| and whitespaces with underscores
str=ReReplace(str,"[*?\""]","","ALL");
str=ReReplace(str,"\s","_","ALL");
str=ReReplace(str,"[:<>|]","-","ALL");
str=Replace(str,"\","_-_","ALL");
str=Replace(str,"/","_-_","ALL");
// leading period is also invalid for MACs
return str;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment