2
>>> pypyodbc.win_create_mdb('E:/Database/Japan/201112.mdb')

Its working fine for double-levels but there is an error when I create tripper-level folders error. Would you shade me a light> Thanks. MS Access library for python

>>> import pypyodbc    
>>> pypyodbc.win_create_mdb('E:/Database/Japan/JLeague/201112.mdb')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Anaconda\lib\site-packages\pypyodbc-1.3.1-py2.7.egg\pypyodbc.py", line 2715, in win_create_mdb
    raise Exception('Failed to create Access mdb file - "%s". Please check file path, permission and Access driver readiness.' %mdb_path)
Exception: Failed to create Access mdb file - "E:/Database/Japan/JLeague/201112.mdb". Please check file path, permission and Access driver readiness.
Community
  • 1
  • 1

1 Answers1

3

win_create_mdb will not automatically create a directory if it does not already exist, so you need to check that and possibly create the directory yourself before trying to create the database file within it. Try something like this

# -*- coding: utf-8 -*-
import os
import pypyodbc
directory = 'E:/Database/Japan/J League/'
if not os.path.exists(directory):
    os.makedirs(directory)
pypyodbc.win_create_mdb('"' + directory + '201112.mdb' + '"')
Gord Thompson
  • 116,920
  • 32
  • 215
  • 418
  • Thanks dude, the answer should be workable but wondered why there is a syntax error... >>> import os >>> import pypyodbc >>> directory = 'E:/Database/Japan/JLeague/' >>> if not os.path.exists(directory): ... os.makedirs(directory) ... pypyodbc.win_create_mdb(directory + '201112.mdb') File "", line 3 pypyodbc.win_create_mdb(directory + '201112.mdb') ^ SyntaxError: invalid syntax – ケンジ リュスケ Mar 23 '14 at 10:38
  • it works now, I tried to use spacing folder name got failed. folder name without spacing is workable. – ケンジ リュスケ Mar 24 '14 at 09:26
  • @ケンジリュスケ I have updated my answer so that it works when the file path includes spaces. – Gord Thompson Mar 24 '14 at 09:42