Hunzla Ali
Hunzla Ali

Reputation: 423

No such a file or directory in Azure Function

I have create azure function. In that function I have different folders in which some files exists. After deployment to azure portal, I cannot see any folder/directory in that function. enter image description here

I am trying to write file in one of those folders. But when it try to write it, it throws exception "No such file or directory" enter image description here

Here is my azure function structure: enter image description here

When I try to access any of the folder like "./model_weights/teacher", it throws "No such file or directory" exception.

Here is the code:

enter image description here

How can i access any of the folder in azure function?

Upvotes: 3

Views: 3771

Answers (1)

Ecstasy
Ecstasy

Reputation: 1864

The error traces to /home/site/wwwroot/ directory, to fix this, you can access root directory using abspath:

import os
ROOT_DIR = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

You can refer to How To Access Azure Functions wwwroot Folder, How to access file in root directory in function app and Get root directory of Azure Function App v2

Upvotes: 2

Related Questions