Skip to content

Commit 730b0c6

Browse files
committed
Added docs for getting the script path and/or folder. Fixes dotnet-script#137
1 parent f9b9e88 commit 730b0c6

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ That is a pretty long URL, so why don't make it a [TinyURL](https://tinyurl.com/
259259
dotnet script https://tinyurl.com/y8cda9zt
260260
```
261261

262+
### Script Location
263+
264+
A pretty common scenario is that we have logic that is relative to the script path. We don't want to require the user to be in a certain directory for these paths to resolve correctly so here is how to provide the script path and the script folder regardless of the current working directory.
265+
266+
```c#
267+
public static string GetScriptPath([CallerFilePath] string path = null) => path;
268+
public static string GetScriptFolder([CallerFilePath] string path = null) => Path.GetDirectoryName(path);
269+
```
270+
271+
> Tips: Put these methods as top level methods in a separate script file and `#load` that file wherever access to the script path and/or folder is needed.
272+
262273

263274

264275
## REPL

0 commit comments

Comments
 (0)