How to verify if a string is a valid filename and/or path

Yeah I wouldn’t suggest doing this either. On Windows you can easily check for the presence of the disallowed characters and reject names with those early. On Unix the only disallowed character is nul. However, there are other restrictions you can’t know beforehand. Apart from some otherwise valid names being disallowed on Windows (nul, aux, com1, …) the filesystem may enforce UTF-8 for example. A valid file name may also not work due to permissions, or a file being “in the way” of a required directory.

Calling os.Stat would be my way to check. Nil error or os.IsNotExist probably indicates a valid file name. Other errors indicate a problem.