Forum Discussion
VS Code Integration. Spark.SQL Query working whereas Relative Filepath is not
The first two lines are working fine on powerbi.com in the browser, and not in VS Code.
The second two lines are working fine in both.
How can I get the relative path to work in VS Code? Happy to use a workaround if necessary (e.g Absolute path).
- Anonymous2 years ago
Hi matthewstainsby
We don't support mssparkutils or mount lakehouse in VS Code currently, so you cannot do these file system operations in our extension. You can do these concat operations on Fabric Portal, and then read these data in VSCode.
Here is Lakehouse public api:
Items - List Lakehouses - REST API (Lakehouse) | Microsoft Learn
You can use this to list lakehouses files too.
Hope this helps. Please let me know if you have any further questions.
10 Replies
- AnonymousNot applicable
Thanks for using Fabric Community.
Can you please tell me what the get_ folder_contents function does? Please share the code, so I can understand better.
Thanks
- matthewstainsbyFrequent Visitor
Hello!
The function below is returning a file not found error:
[Errno 2] No such file or directory: '/lakehouse/default/Files/PDS_Files/'
However, when I use the same filepath in the Power BI service, the function is correctly returning the list of files.def get_folder_contents(pds_dir): """Return a list of filepaths in the current directory. Ignores subdirectories.""" f_paths = [] for filename in os.listdir(pds_dir): file_path = os.path.join(pds_dir, filename) if os.path.isfile(file_path): f_paths.append(file_path) return f_paths- AnonymousNot applicable
Hi matthewstainsby
Thanks for the details.
Fabric mounts the default lakehouse in to notebook, so you can read files in default lakehouse by absolute path '/lakehouse/default/'. But this method doesn't work in VS Code by design.
You can use spark api to read file/folder in VS Code.
Load data into your Lakehouse with a notebook - Microsoft Fabric | Microsoft Learnexample:
df = spark.read.format("csv").option("header","true").load("Files/car_purchasing.csv")
Hope this helps. Please let me know if you have any further questions.