2017-10-18 47 views

回答

1

目前,找出當前正在執行的腳本目錄的最佳方式是非常冗長的。我不知道是否有一些快捷方式/內置的,我不知道,但這裏有雲:

GetMineDirectory.csx

#!/usr/bin/env csi 

using System; 
using System.IO; 
using System.Runtime.CompilerServices; 

static string GetMyPath(
    [CallerFilePath] string path = "") 
    => path; 

// Do not write in terms of GetMyPath() in case we are called from another script. 
static string GetMyDirectory(
    [CallerFilePath] string path = "") 
    => Path.GetDirectoryName(path); 

Console.WriteLine($"My full path is {GetMyPath()}"); 

Console.WriteLine($"My directory is {GetMyDirectory()}"); 
相關問題