-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Convert Windows path to Posix path #87
Comments
This comment has been minimized.
This comment has been minimized.
Nicer way 🚀 : using FilePathsBase
GoodPath(inp::String) = inp |> Path |> _GoodPath |> string
_GoodPath(path::WindowsPath) = PosixPath((path.drive, path.segments...))
_GoodPath(path) = path GoodPath makes a path good. 🙅♂️ julia> GoodPath("C:\\folder1\\folder2")
"C:/folder1/folder2"
julia> GoodPath("folder1/foldee2")
"folder1/foldee2" |
Hmmm, might need more context on your use case. Why are you wanting to convert windows to posix paths? My first instinct is that we could support a NOTE: Your example could be simplified to a call to |
To write generic code that works on all platform I need a single method of writing paths. I chose the Posix method since Julia works well with it. I used FilePathsBase methods to make a path from a string, and then dispatch on it based on the types that it detects, and then convert it back to string for my usage. I do a lot of string interpolation, printing, etc, so I can't use FilePaths for that, and I should use strings.
The benefit of using FilePathsBase is its path detection regardless of what is given inside: julia> using FilePathsBase
julia> p = Path("C:\\folder1/folder2")
p"C:/folder1/folder2"
julia> typeof(p)
WindowsPath
Yeah probably. I am not concerned with speed here. IMO, this sentence questions the existence/implementation of FilePaths and FilePathsBase itself. |
I'll note that your issue with interpolation wasn't clarified here, but did come up on discourse. It isn't that you need to convert Windows to Posix paths, but rather that you want
That's just one of many benefits, but if you like that feature then I'm glad it helps.
How so? It's about using the right tool for the job. NOTE: Please don't continue posting to both the issue and discourse as it increases the likelihood that I'll miss something in your issue/request. |
How can we convert the Windows path to the Posix path?
The text was updated successfully, but these errors were encountered: