Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Databricks: How do I get path of current notebook?

Databricks is smart and all, but how do you identify the path of your current notebook? The guide on the website does not help.

It suggests:

%scala
dbutils.notebook.getContext.notebookPath
res1: Option[String] = Some(/Users/[email protected]/my_test_notebook)

This does not give me the complete path, but rather the path to some folder structure that is not accessible from the notebook. I need the path, such that I can make system calls in the same folder as the .ipynb file.

Any suggestions?

like image 843
Esben Eickhardt Avatar asked Nov 28 '18 16:11

Esben Eickhardt


People also ask

How do you give relative paths in Databricks?

To specify a relative path, preface it with ./ or ../. For example, if notebookA and notebookB are in the same directory, you can alternatively run them from a relative path.

What does Dbutils fs ls return?

ls command (dbutils.fs.ls)Lists the contents of a directory. To display help for this command, run dbutils.

What is %FS in Databricks?

The Databricks File System (DBFS) is a distributed file system mounted into an Azure Databricks workspace and available on Azure Databricks clusters.


1 Answers

You can retrieve the information by using dbutils command:

dbutils.notebook.entry_point.getDbutils().notebook().getContext().notebookPath().get()
like image 165
Federico Raimondi Cominesi Avatar answered Oct 08 '22 19:10

Federico Raimondi Cominesi