[英]F# Directory and paths in MacOS X 10.11.3
嗨,我是 MacOS X (10.11.3) 的新手,到目前為止在 Win8.1 上的 VS2015 中使用過 F#
我有一些問題:
1- 在 F# Interactive 中,如果我想說,有目錄 ~/Documents 的文件列表
Directory.GetFiles(@"~/Documents")
不起作用。 什么是正確的語法?
如果我想做一個#r xxx.dll
,我該如何正確指定路徑
2- 源文件(.fs 或 .fsx)中的相同問題
謝謝
編輯例如我在 F# 交互式中得到以下內容
讓 CD = "/文件";;
val CD : string = "/Documents"
Directory.GetFiles(CD);;
System.IO.DirectoryNotFoundException: 找不到目錄“/Documents”。
在 System.IO.Directory.ValidateDirectoryListing (System.String path, System.String searchPattern, System.Boolean& stop) <0x1a22580 + 0x001f8> in 0 at System.IO.Directory.GetFileSystemEntries (System.String path, System.String searchPattern, FileAttributes mask, FileAttributes attrs) <0x1a22800 + 0x00061> in 0 at System.IO.Directory.GetFiles (System.String path, System.String searchPattern) <0x1a21bf0 + 0x00034> in 0 at System.IO.Directory.GetFiles (System. String path) <0x1a21bb0 + 0x00027> in 0 at FSI_0031.main@ () <0x73a07f0 + 0x00013> in 0 at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection,objectMonoMethod,object) [],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfoculture) <0x1a7c850 + 0x000a1>在 0 由於錯誤而停止
我假設您可能正在使用 Mono/Xamarin? 我沒有使用 MacOS 的經驗,但 .NET 應該可用。 您可以使用以下命令訪問您的主目錄: System.Environment.GetEnvironmentVariable("USERPROFILE")
還有其他變量訪問特殊文件夾,但我不確定 Windows 是如何特定的。 對於第二個問題,您可以使用#I @"path/to/dll"
指定 dll 所在的文件夾,然后使用#r @"file.dll"
添加 dll 名稱。 這適用於 fs 和 fsx 文件。 你可能想把它放在#if INTERACTIVE #endif
塊之間。 對於已編譯的內容,您可以直接在 IDE 中添加對 DLL 的引用。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.