Ivan Krecker
Ivan Krecker

Reputation: 5

How do I change path directory in Jupyter lab?

How do I change initial path directory in Jupyter lab, when i want to get a file via "~/"?

enter image description here

Have tried to generate config, and then change some parameters but only got confused.

Upvotes: 0

Views: 584

Answers (2)

Elkhan
Elkhan

Reputation: 369

You can change file directory like that.

import shutil

File= r'C:\Users\ivan\Desktop\Somewhereidonotknow\example.csv'
Whereyou_want= r'C:\Users\ivan\Desktop\example.csv'

shutil.move(File, Whereyou_want)

Upvotes: 1

Wayne
Wayne

Reputation: 9810

You should be using the %cd magic command to change the working directory. And then to set up using tab completion, you'd start by typing ./ before hitting tab at the place where you want to choose your CSV file.

In the demonstration set-up for the screenshot below I made a test directory in the root (home) location and made two CSV files in there.

Using %cd test first I am then able to use tab completion to get the option to select one of the two CSV files: enter image description here

I probably should have included running pwd to 'print the working directoryafter I ran the%cd test` command to demonstrate things more fully.

Before I executed the command %cd test, the tab-completion was showing the root (home directory) when I tried for tab completion.

enter image description here



The tilde symbol (~) always means the HOME directory on the system. It won't change. So you were always specifying to start in HOME in your example in your post, no matter what the current working directory is in the notebook's active namespace. You want to use relative paths for when the working directory has been adjusted.



There are more complex settings you can take advantage of using inside the notebook in conjunction with the %cd magic.

For example, this post and answer shows how you can use the %boookmark magic to set assign a directory to a bookmark setting and then you can more easily switch around to various directories using %cd.

Upvotes: 1

Related Questions