How to get the path of files using python os library
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 06:29 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-31-2018 10:42 AM
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.
reference documentation
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-06-2019 02:53 AM
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'
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-05-2020 11:58 PM
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)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 02:28 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
09-07-2020 12:50 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-15-2022 02:28 PM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-16-2022 07:50 AM

