1

I'm trying to change the directory to the folder that contains the folder I'm in.

That is, I'm in /Users/ethanfuerst/Documents/Coding/mpgdata and I'm trying to go back to /Users/ethanfuerst/Documents/Coding and access a text file in the Coding folder.

When I run this code:

import os print(os.getcwd()) os.chdir('⁨Users/ethanfuerst/Documents/Coding') 

I get this output and error

/Users/ethanfuerst/Documents/Coding/mpgdata --------------------------------------------------------------------------- FileNotFoundError Traceback (most recent call last) <ipython-input-19-6c6ee01785f6> in <module> 1 import os 2 print(os.getcwd()) ----> 3 os.chdir('⁨Users/ethanfuerst/Documents/Coding') FileNotFoundError: [Errno 2] No such file or directory: '\u2068Users/ethanfuerst/Documents/Coding' 

Does anyone know why this could be the case?

Edit: forgot to mention I am on a Mac

2 Answers 2

1

Try using C:\ in front of Users. If that does not work, try using .. in the directory specification to go back one directory.

Sign up to request clarification or add additional context in comments.

3 Comments

.. worked! I didn't know you could use that command with os to go back a directory. Thanks!
I forgot to mention I'm on a mac. How can I go forward in to the mpgdata folder? Adding C:\ didn't work.
I was able to do it with os.chdir("/Users/ethanfuerst/Documents/Coding/mpgdata")
0

Use double quotes os.chdir("⁨Users/ethanfuerst/Documents/Coding") instead of os.chdir('⁨Users/ethanfuerst/Documents/Coding')

5 Comments

Are you using Windows? The accepted answer uses windows C:\ but you have forward slash which would denote Mac or Linux - not windows
I forgot to mention I'm on a mac. How can I get back in to the mpg directory after I .. out of it?
A shortcut in the terminal to get back to the previous directory is "cd -"
I was able to do it with os.chdir("/Users/ethanfuerst/Documents/Coding/mpgdata")
I believe that is essentially what I wrote above.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.