【发布时间】: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”的目录