Have you tried filepath <https://golang.org/pkg/path/filepath/> package 
from path <https://golang.org/pkg/path/>. It handles such things based on 
OS & etc. Hope it helps

On Monday, 6 August 2018 06:49:15 UTC+4:30, DrGo wrote:
>
> In many applications, I need to resolve an arbitrary file name that a user 
> provided to a valid file-system path that can be used to open, create or 
> append to a file. I think I now have written 4 funcs to achieve one or 
> another of these objectives, but none that is flexible enough and robust 
> enough to cope with most common scenarios. Do you know of a well-tested 
> func that does the following:
> - can resolve a filename to a path whether the provided filename is 
> absolute, relative to a provided default directory or the working dir 
> (e.g., ../../fname, just fname etc) if the default directory is an empty 
> string.
> - return an error if the filename cannot be resolved eg due to malformed 
> path
> - check if the file must not exist, must exist, must be a file (or 
> directory) etc as specified.
>
> I am thinking that some of the more complex applications out there (eg 
> docker, go build tools) must have implemented a similar function, and was 
> hoping someone could point me in the right direction.
>
> Thanks,
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to