How to save a file into a directory in Jupyter notebook?

There are two methods:
1.You can use the magic command %notebook to save as ipynb

  %notebook "directory/to/file/filename.ipynb"     

2.You can use the magic command %%writefile to save as py file

  %%writefile "directory/to/file/filename.py"

In the second method, you should put this command at the top of the cell, otherwise it will throw an error.


It is easiest to select a destination before you create a program using Jupyter Notebook; as then you do not run into this issue.

However, since you have already made a program, one possible solution is to make a copy of the file, move it to your desired location, and then delete the old file. Before doing this, ensure that you have saved it first, otherwise data might be lost.


You can save a notebook to a location of your choice by using the "File" -> "Download as" -> "Notebook (.ipynb)" option from the menu.

Alternatively you can start your notebook server from a different directory and it will save all notebooks to that directory.

A third option is to navigate to the directory you want the notebook to be saved to in the tree view "http://127.0.0.1:8888/tree" prior to creating the notebook.