0

When I run this code:

script_path = os.path.realpath(__file__)
new_abs_path = os.path.join(script_path, 'Users')
if not os.path.exists(new_abs_path):
    os.makedirs(new_abs_path)

I get this error:

FileNotFoundError: [WinError 3] The system cannot find the path specified '<script drive>\\<script path>\\<script filename>\\User'

2 Answers 2

3

Since you use Python 3.9, you can use Path.mkdir:

from pathlib import Path

path = Path(__file__).parent / 'Users'
path.mkdir(exist_ok=True)

I strongly advise you to use pathlib.Path, it provide very useful tools to manipulate path, files and directories.

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

Comments

1

Try this:

import os
os.makedirs(os.path.join(os.path.dirname(__file__), 'Users'), exist_ok=True)

You forget to take the directory of your python script. You can t create a folder inside a file...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.