I have a file located in a solution directory like this:
I want to read the contents of one of the .txt files into a string in the FSI:
open System.IO
[<Literal>]
let path = "../Data/Build_Keynote2014.txt"
let buildKeynote = File.ReadAllText(path)
The problem is that it is throwing an exception:
System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Users\jamie\AppData\Local\Data\Build_Keynote2014.txt'.
Is there a way to reference the file without using the full path?
Thanks
After some research, I found this post
let baseDirectory = __SOURCE_DIRECTORY__
let baseDirectory' = Directory.GetParent(baseDirectory)
let filePath = "Data\Build_Keynote2014.txt"
let fullPath = Path.Combine(baseDirectory'.FullName, filePath)
let buildKeynote = File.ReadAllText(fullPath)
works like a charm. Thanks everyone who submitted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With