3
$\begingroup$

I get get notebook location with NotebookDirectory\[\]

How to get m-file location from within it?

$\endgroup$
1
  • $\begingroup$ FileNames["*.m", NotebookDirectory[]]? $\endgroup$
    – kglr
    Commented Oct 18, 2017 at 17:29

1 Answer 1

5
$\begingroup$

You can use

DirectoryName[$InputFileName]
$\endgroup$
1
  • 4
    $\begingroup$ @Dims It is good to know that this works only if evaluated while the file is being loaded. A common mistake is to define packDir[] := DirectoryName[$InputFileName] in the package, then try to use packDir[] after the package has already loaded. Instead, do $packDir = DirectoryName[$InputFileName]; packDir[] := $packDir in the package. $\endgroup$
    – Szabolcs
    Commented Oct 18, 2017 at 17:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.