cancel
Showing results forย 
Search instead forย 
Did you mean:ย 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results forย 
Search instead forย 
Did you mean:ย 

How to get the path of files using python os library

sp3234
New Contributor

unable to find the path to directory with os library

0693f000007OoJdAAK

7 REPLIES 7

User16752239222
Databricks Employee
Databricks Employee

Hi @sp3234โ€‹ 

When using the local file APIs to read and write to dbfs paths, you should reference using "/dbfs/..." rather than "dbfs/..."

Here's an example that compares the result of local file APIs to using the %fs magic keyword in a notebook cell.

screen-shot-2018-08-31-at-103435-am.png 

reference documentation

Wistech_biz
New Contributor II

Being a web developer I've used this:

>>> import os >>> os.path.abspath("C:/example/cwd/mydir/myfile.txt") 'C:/example/cwd/mydir/myfile.txt'

rickwilliam
New Contributor II

I am working with Magento 2 extensions development company and i am a python developer since 5 years here is my answer.

 Python program to explain os.getcwd() method 

# importing os module 
import
os 

# Get the current working 
# directory (CWD) 
cwd 
=
os.getcwd() 

# Print the current working 
# directory (CWD) 
print
(
"Current working directory:"
) 
print
(cwd) 

Hi,

os.getcwd() simply prints '/databricks/driver' for me irrespective of the location of the file..

Ideally I would like to get "/dbfs/FileStore/shared_uploads/krishna@company.com/Project_Folder"

Thanks

tomjenner
New Contributor II

In my opinion, it's hard to get the path of files using python os library. As a programmer who is engaged in software development for small business, I'm interested in the answer too.

Hi mate, did you get the answer?

os.getcwd() simply prints '/databricks/driver' for me irrespective of the location of the file..

Ideally I would like to get "/dbfs/FileStore/shared_uploads/krishna@company.com/Project_Folder"

Thanks

Aviral-Bhardwaj
Esteemed Contributor III

@sp3234โ€‹ 

Please use this it will work

image

AviralBhardwaj

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you wonโ€™t want to miss the chance to attend and share knowledge.

If there isnโ€™t a group near you, start one and help create a community that brings people together.

Request a New Group