Creating a folder in the "AppData\Roaming" directory [Python]
Asked Answered
Q

1

7

Is there actually a way of doing this? I've tried using the following code:

file_path = os.environ['APPDATA'] + "\\Example\\example.db" sqlite3.connect(file_path)

But it comes up with an error. My only thought would be that it's permissions-related, but if that was the case, then I probably wouldn't create a file there, either... I'm stumped. Anyone got any idea?

Quincuncial answered 13/2, 2014 at 18:0 Comment(0)
H
11

Try like this,

import os
dir_path = '%s\\Example\\' %  os.environ['APPDATA'] 
if not os.path.exists(dir_path):
    os.makedirs(dir_path)

file_path = '%sexample.db' % dir_path
sqlite3.connect(file_path)
Handbreadth answered 13/2, 2014 at 18:3 Comment(1)
And for those used to using os.path.join: dir_path = os.path.join(os.environ['APPDATA'], 'Example').Visit

© 2022 - 2024 — McMap. All rights reserved.