How to get location of Neo4j 'imports' folder of a DB programmatically?

Hi,

I am using Neo4j Desktop 1.3.11 on Windows.
Am using apoc.export.csv.query() to get my query results via py2neo. This outputs the csv file to the "import" folder of the DB.

Understand it is possible to navigate to the DB's "import" folder by clicking the 'Open Folder' button in Neo4j Desktop. However, I would like to do so programmatically, since my program is aware of the DB's name e.g. neo4j-db, instead of manually specifying the DB's folder location, which naming can be quite obtuse e.g. C:\Users\[username]\AppData\Local\Neo4j\Relate\Data\dbmss\dbms-db3c8764-9a9c-xxx

I did a couple of searches on Google as one in this community forum, but didn't find anything that can do that.

Is there a way, perhaps to call the system graph to check the folder path?
Or perhaps I'm asking the wrong qn -> Is there a way to specify an arbitrary location in Windows to output my csv?

cypher

Call dbms.listConfig();

Should list all config parameters and values. You should be able to get import dir from here

1 Like

To be more complete:

Call dbms.listConfig() YIELD name, value
WHERE name='dbms.directories.import'
RETURN value

value contains the string of the import directory.

You can also set your import directory in configs

  1. Click on the 3 dots next to DB name
  2. Click on settings
  3. search for: dbms.directories.import=
  4. uncomment it and set it:
    dbms.directories.import=ABSOLUTE_DIRECTORY_PATH

Also see:

3 Likes

Hi,

Slight tweak to the solution. This call just produces the relative path of the import folder.

Call dbms.listConfig() YIELD name, value
WHERE name='dbms.directories.import'
RETURN value

The returned values is "import" which is probably not the intent of the request which I take to need the full path.

This returns the full path:

Call dbms.listConfig() YIELD name, value
WHERE name='dbms.directories.neo4j_home'
RETURN value

and since the folder structure is fixed by the database creation process and the import folder name is "import" so that needs to be added to the end of the returned string.
So this is where I ended up with

def get_import_path(tx):
    result= tx.run("Call dbms.listConfig() YIELD name, value WHERE name='dbms.directories.neo4j_home' RETURN value")
    return [record["value"] for record in result]

with driver.session() as session:
    Neo4JImport = session.read_transaction(get_import_path)[0]+'/import'
driver.close()
Neo4JImport

Andy