【问题标题】:F# Directory and paths in MacOS X 10.11.3MacOS X 10.11.3 中的 F# 目录和路径
【发布时间】:2016-07-22 01:11:48
【问题描述】:

您好,我是 MacOS X (10.11.3) 的新手,目前在 Win8.1 上的 VS2015 中使用过 F#

我有一些问题:

1- 在 F# Interactive 中, 如果我想说,有目录的文件列表 ~/Documents

Directory.GetFiles(@"~/Documents") 不起作用。什么是正确的语法?

如果我想做#r xxx.dll,如何正确指定路径

2- 源文件(.fs 或 .fsx)中的相同问题

谢谢

例如编辑我在 F# 交互中得到以下内容

让 CD = "/Documents";;

val CD : string = "/Documents"

Directory.GetFiles(CD);;

System.IO.DirectoryNotFoundException:找不到目录“/Documents”。

在 System.IO.Directory.ValidateDirectoryListing (System.String path, System.String searchPattern, System.Boolean& stop) in 0 在 System.IO.Directory.GetFileSystemEntries (System.String path, System.String searchPattern, FileAttributes mask, FileAttributes attrs) in 0 在 System.IO.Directory.GetFiles (System.String path, System.String searchPattern) in 0 在 System.IO.Directory.GetFiles (System.String 路径) in 0 在 FSI_0031.main@ () 在 0 在(包装器托管到本机) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&) 在 System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] 参数, System.Globalization.CultureInfo 文化) in 0 由于错误而停止

【问题讨论】:

  • 当您说不起作用时 - 会发生什么? 2 - 您需要引号中的目录名称
  • 抱歉 - 对于 2,它应该是引号中的 dll 名称 - 比如 #r "file.dll"
  • 谢谢!那么,该 /Documents 文件夹是否存在?或者它是某种特殊的文件夹?你可以试试Path.Combine(Environment.GetFolderPath (Environment.SpecialFolder.Personal),"Documents") 来自stackoverflow.com/questions/1933975/…
  • 另外,因为您将访问带有 \ 或 / 的路径,所以我会使用 let mydir = @"/Documents"
  • 我是 MacOS X 的菜鸟,但如果我打开终端,我输入“ls”,我肯定会看到一个名为“Documents”的目录

标签: macos file path f#


【解决方案1】:

我假设您可能正在使用 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 的引用。

【讨论】:

    猜你喜欢
    • 2017-01-31
    • 1970-01-01
    • 2015-08-22
    • 2020-03-13
    • 2010-11-29
    • 1970-01-01
    • 2017-10-12
    • 2011-12-11
    • 2016-11-10
    相关资源
    最近更新 更多