#Manipulating Windows paths from Linux target?

13 messages · Page 1 of 1 (latest)

next igloo
#

I need to manipulate Windows paths whilst running in Linux. In the stdlib, the PathBuf uses whichever convention the target os uses. I would rather not resort to just using Strings if possible. Is there e.g. a popular crate which provides path manipulation for arbitrary platforms? Thanks

bitter salmon
#

In the stdlib, the PathBuf uses whichever convention the target os uses.
It seems like you can do cross platform path manipulation with this just fine, looking at the docs of push and pop of it.

next igloo
graceful coral
#

Are you able to just use / on windows?

next igloo
#

yeah, it's the pop I'm more worried about

graceful coral
#

Wondering if there's any issue with replacing all \ with / before turning it into a PathBuf

next igloo
#

tbh there probably isn't lol
that would work, although just a little janky

#

it would be helpful since I'm not sure the backslash won't break some stuff down the line

graceful coral
#

Do you know ahead of time what OS the path came from?

next igloo
#

for context: my program is running on a Linux box which is talking to some other programs on a Windows box. The programs in Windows send me messages with windows paths in them, I translate that path to the same file share mounted in Linux to read some files. Then I write some files to the share. Then I talk again to the same programs on the same windows box telling them where I put files BUT from their perspective in windows-land. It's a real dumb way to do things, but it's out of my control

graceful coral
#

Do you control the program on the windows boxes? Can you just have them send pre-split paths?

next igloo
#

that's what I suggested to my boss 😄
nope lol

graceful coral
#

I'm kinda leaning toward the straightforward replace method. You'll have to handle the drive letter but I'm guessing you already have that covered. Second best would be a crate.