Skip to content

Instantly share code, notes, and snippets.

@ranskills
Last active September 4, 2023 12:37
Show Gist options
  • Save ranskills/84b888af24cfea74c1818ffa3a1e4ff4 to your computer and use it in GitHub Desktop.
Save ranskills/84b888af24cfea74c1818ffa3a1e4ff4 to your computer and use it in GitHub Desktop.
import "regexp"
var r, _ = regexp.Compile("\\\\|/|:|\\*|\\?|<|>")
// MakeFilenameWindowsFriendly removes characters not permitted in file/directory names on Windows
func MakeFilenameWindowsFriendly(name string) string {
return r.ReplaceAllString(name, "")
}
@curiosport
Copy link

Hi champ, you missed the quotation marks (") and the pipe symbol (|). Among other things:
https://stackoverflow.com/a/31976060
https://en.wikipedia.org/wiki/Filename#Reserved_characters_and_words

@ranskills
Copy link
Author

@curiosport Good observation.
I was not targeting a full-proof implementation because I had some files from a Windows machine I was processing and this sufficed, but I may update this based on the resources you shared.

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment