Skip to content
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

Make it easy to extract a file path as Text from a FilePath #97

Closed
rpglover64 opened this issue Aug 18, 2015 · 3 comments
Closed

Make it easy to extract a file path as Text from a FilePath #97

rpglover64 opened this issue Aug 18, 2015 · 3 comments

Comments

@rpglover64
Copy link
Contributor

AFAICT, there's no easy (and discoverable) way to get a function :: FilePath -> Text; the closest thing I can find is fromRight . toText, which involves using the (now deprecated) package system-filepath directly as well as an unsafe function (which, apparently, is not provided by base).

@PierreR
Copy link
Contributor

PierreR commented Aug 18, 2015

You can use fp :: Format r (FilePath -> r)

import Filesystem.Path.CurrentOS((</>))
format fp ("usr" </> "lib")

That said there is an issue about replacing system-filepath (#54)

I believe your issue is a duplicate to #67

@Gabriella439
Copy link
Owner

I think I should probably expand the tutorial to mention the format fp trick and maybe also include an example of its use in Turtle.Prelude to ensure that people don't miss this. I agree that it's a pretty common idiom that is hard to discover.

@PierreR
Copy link
Contributor

PierreR commented Sep 6, 2018

As a note, given 'p' of type FilePath and 't' of type Text, the only way to safely handle the concatenation of those values is:

format fp (p </> fromText t)

I believe it is too much of a trouble for bash scripting but that's another story.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants