[英]F# Directory and paths in MacOS X 10.11.3
Hi i'm a newbie in MacOS X (10.11.3) and have used so far F# in VS2015 on Win8.1嗨,我是 MacOS X (10.11.3) 的新手,到目前为止在 Win8.1 上的 VS2015 中使用过 F#
I have some questions:我有一些问题:
1- in F# Interactive, if i wanna say, have the list of files of the directory ~/Documents 1- 在 F# Interactive 中,如果我想说,有目录 ~/Documents 的文件列表
Directory.GetFiles(@"~/Documents")
doesn't work. Directory.GetFiles(@"~/Documents")
不起作用。 What is the right syntax ?什么是正确的语法?
if i want to do a #r xxx.dll
, how do i specify rightly the path如果我想做一个
#r xxx.dll
,我该如何正确指定路径
2- same question in a source file (.fs or .fsx) 2- 源文件(.fs 或 .fsx)中的相同问题
thanks谢谢
EDIT for example I get the following in F# interactive编辑例如我在 F# 交互式中得到以下内容
let CD = "/Documents";;
让 CD = "/文件";;
val CD : string = "/Documents" val CD : string = "/Documents"
Directory.GetFiles(CD);;
Directory.GetFiles(CD);;
System.IO.DirectoryNotFoundException: Directory '/Documents' not found. System.IO.DirectoryNotFoundException: 找不到目录“/Documents”。
at 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.MonoMethod,object,object[],System.Exception&) at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x1a7c850 + 0x000a1> in 0 Stopped due to error
在 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 由于错误而停止
I assume maybe you're using Mono/Xamarin?我假设您可能正在使用 Mono/Xamarin? I don't have experience with MacOS but .NET should be available.
我没有使用 MacOS 的经验,但 .NET 应该可用。 You can access your home directory with:
System.Environment.GetEnvironmentVariable("USERPROFILE")
There are also other variables accessing special folders but I'm not sure how windows specific is that.您可以使用以下命令访问您的主目录:
System.Environment.GetEnvironmentVariable("USERPROFILE")
还有其他变量访问特殊文件夹,但我不确定 Windows 是如何特定的。 For your second question you can use #I @"path/to/dll"
to specify the folder where the dll is and then add the dll name with #r @"file.dll"
.对于第二个问题,您可以使用
#I @"path/to/dll"
指定 dll 所在的文件夹,然后使用#r @"file.dll"
添加 dll 名称。 This works in both fs and fsx files.这适用于 fs 和 fsx 文件。 You might want put this in between
#if INTERACTIVE #endif
block.你可能想把它放在
#if INTERACTIVE #endif
块之间。 And for compiled stuff you can add the reference to the DLL in your IDE directly.对于已编译的内容,您可以直接在 IDE 中添加对 DLL 的引用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.